tp5支付宝企业转账到商户

<?php
namespace app\common\model;

require_once "extend/wx/lib/WxPay.Api.php";
use think\Db;
use alipay\aop\AopClient;
use alipay\aop\request\AlipayFundTransToaccountTransferRequest;

class Pay extends Base
{
	/**
     * 支付宝企业转账到商户
     * @return [store_member_id] [商户ID]
     * @return [userid] [商户支付宝userID]
     * @return [money] [支付金额]
     */
    public function accounts($store_member_id='',$userid='',$money='')
    {
		if ($userid) {
			$aop = new AopClient ();
			$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do'; //请求url
			$aop->appId = config('alipay_id');        //商家支付宝APPID
			$aop->rsaPrivateKey = config('private_key');    //支付宝私钥
			$aop->alipayrsaPublicKey=config('public_key');    //支付宝公钥
			$aop->apiVersion = '1.0';    //版本号
			$aop->signType = 'RSA2';    //加密方式
			$aop->postCharset='utf-8';    
			$aop->format='json';  //支付宝返回方式
			$out_biz_no = substr(build_order_no().uniqid(),0,32);    //订单号
			$request = new AlipayFundTransToaccountTransferRequest();
			$request->setBizContent("{" .
			"\"out_biz_no\":\"".$out_biz_no."\"," .
			"\"payee_type\":\"ALIPAY_USERID\"," .
			"\"payee_account\":\"".$userid."\"," .
			"\"amount\":\"".$money."\"," .
			"\"payer_show_name\":\"公司名\"," .
			// "\"payee_real_name\":\"张三\"," .
			"\"remark\":\"转账备注\"" .
			"}");
			$result = $aop->execute ( $request); 
			$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
			$resultCode = $result->$responseNode->code;
			$result = json_decode(json_encode($result),true);
			if(!empty($resultCode)&&$resultCode == 10000){
				//转账记录入库
				$data['code'] = 1;
				$data['msg'] = '支付成功';
				$data['out_biz_no'] = $out_biz_no;
				return json_encode($data);
			} else {
				$data['code'] = 0;
				$data['msg'] = $result['alipay_fund_trans_toaccount_transfer_response']['sub_msg'];
				return json_encode($data);
			}
		}else{
			$data['code'] = 4;
			$data['msg'] = '请先绑定支付宝';
			return json_encode($data);
		}
    }
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

饭饭咿呀呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值