支付宝提现参考(企业付款)

2020-05-06 17:21:29 浏览2042次 作者: 青星

收藏

1. 支付宝商户平台开通企业付款接口

2. 接口签名和验签方式需要使用证书加签和验签(证书生成工具下载地址https://ideservice.alipay.com/ide/getPluginUrl.htm?clientType=assistant&platform=win&channelType=WEB)

3. 通过签名工具生成证书,上传到支付宝商户平台处,保存好账户的支付宝公钥证书、应用公钥证书和应用私钥

4. 官方下载phpsdk(https://opendocs.alipay.com/open/54/103419/),sdk中包含了所有的调用方式和示例文件

5. 发起转账的时候需要使用AopCertClient(带证书版)去调用,AopClient已经不支持

图片1.png

6. 此处是客户端调用类实例里面发起调用之前的完善方式都有

7. 实际操作

/**
 * @param [] $body 请求数据
 * @param int $type 1 转账到支付宝账户 2 转账到银行卡  3 收发现金红包
 * @param string $identity_type ALIPAY_LOGON_ID 支付宝登录号,支持邮箱和手机号格式   ALIPAY_USER_ID 支付宝的会员ID  默认为支付宝登录号
 * @throws \Exception
 */
public function withdraw($body, $type=1, $identity_type="ALIPAY_LOGON_ID")
{
    require_once EXTEND_PATH."alipay/aop/request/AlipayFundTransUniTransferRequest.php";
    if($type == 1){
        $body['product_code'] = "TRANS_ACCOUNT_NO_PWD";
        $body['biz_scene'] = "DIRECT_TRANSFER";
    }elseif($type == 2){
        $body['product_code'] = "TRANS_BANKCARD_NO_PWD";
        $body['biz_scene'] = "DIRECT_TRANSFER";
    }elseif($type == 3){
        $body['product_code'] = "STD_RED_PACKET";
        $body['biz_scene'] = "PERSONAL_COLLECTION";
        if(!isset($body['original_order_id']) || empty($body['original_order_id'])){
            return ['code'=>0, 'msg'=>"原支付宝业务单号不能为空"];
        }
    }else{
        return ['code'=>0, 'msg'=>"提现类型参数错误"];
    }
    $aop = self::getAop();
    $request = new \AlipayFundTransUniTransferRequest ();
    $bizContent = json_encode($body);
    $request->setBizContent($bizContent);
    $result = $aop->execute ( $request);
    $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
    $resultCode = $result->$responseNode->code;
    if(!empty($resultCode)&&$resultCode == 10000){
        return ['code'=>1];
    } else {
        return ['code'=>0, "msg"=>$result->$responseNode->msg."|".$result->$responseNode->sub_msg];
    }
    
}
static public function getAop()
{
    require_once EXTEND_PATH."alipay/aop/AopCertClient.php";
    $aop = new \AopCertClient();
    $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
    $aop->appId = config("alipay.app_id");
    $aop->rsaPrivateKey = config('alipay.rsaPrivateKey');
    $aop->alipayrsaPublicKey = $aop->getPublicKey(config('alipay.alipay_cert_public_path'));//调用getPublicKey从支付宝公钥证书中提取公钥
    $aop->apiVersion = '1.0';
    $aop->signType = 'RSA2';
    $aop->postCharset = 'utf-8';
    $aop->format = 'json';
    $aop->isCheckAlipayPublicCert = true;//是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内
    $aop->appCertSN = $aop->getCertSN(config('alipay.app_cert_path'));//调用getCertSN获取证书序列号
    $aop->alipayRootCertSN = $aop->getRootCertSN(config('alipay.root_cert_path'));//调用getRootCertSN获取支付宝根证书序列号
    return $aop;
}


当您发现内容错误或代码bug,以及下载链接无法使用等,请点击屏幕右下角的上报错误来进行提交,我们会尽快修正。
本程序所有源码和工具完全免费,当本网站内容如果侵犯了您的权益,请联系我们,我们会尽快处理,感谢您的合作。

收藏 分享

相关文章

评论:

文明上网理性发言,请遵守 新闻评论服务协议

当前还没有评论,快来评论吧

上报错误