wqy
2018-02-25 12:01:00
21456

时间:20210131

 

实现用户提现 资金自动到账

如果能够实现到提现这一步,前期的配置什么的都应该做好了,这里就不赘述了。

当前开发环境:

Windows

phpstudy

ThinkPHP5

 

 

实现提现的步骤 

1 开发者平台进行签约 

2 找到开发文档

3 实际开发测试 

 

 

1 签约

登录支付宝开放平台,进入开发者中心->选择需要对接的APP应用->找到下图界面,进行添加 单笔转账到支付宝账号 功能,然后签约,

2 开发文档,

单笔转账接口是基于支付宝的资金处理能力,为了满足支付宝商家的转账需求,针对有部分开发能力的商家,提供通过API接口完成企业自身支付宝账户到支付宝账户的转账功能。 

 https://opendocs.alipay.com/open/309/106237

https://opendocs.alipay.com/apis/api_28/alipay.fund.trans.uni.transfer

 

 

3 实际开发

在 https://docs.open.alipay.com/54/103419/ 中下载最新demo

   /**
     * 骑士提现到账
     * @param $order_no
     * @param $account
     * @param $price
     * @param $username
     * @return bool
     * @throws \Exception
     */
    public static function withdraw($order_no,$account,$username,$price){

        $aop = new \AopCertClient();
        $appCertPath = config('alipay.appCertPath');//"应用证书路径(要确保证书文件可读),例如:/home/admin/cert/appCertPublicKey.crt";
        $alipayCertPath = config('alipay.alipayCertPath');//"支付宝公钥证书路径(要确保证书文件可读),例如:/home/admin/cert/alipayCertPublicKey_RSA2.crt";
        $rootCertPath =  config('alipay.rootCertPath');//"支付宝根证书路径(要确保证书文件可读),例如:/home/admin/cert/alipayRootCert.crt";

        $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
        $aop->appId = config('alipay.appId');
        $aop->rsaPrivateKey = config('alipay.rsaPrivateKey');
        $aop->alipayrsaPublicKey = $aop->getPublicKey($alipayCertPath);//调用getPublicKey从支付宝公钥证书中提取公钥
        $aop->apiVersion = '1.0';
        $aop->signType = 'RSA2';
        $aop->postCharset='utf-8';
        $aop->format='json';
        $aop->isCheckAlipayPublicCert = true;//是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内
        $aop->appCertSN = $aop->getCertSN($appCertPath);//调用getCertSN获取证书序列号
        $aop->alipayRootCertSN = $aop->getRootCertSN($rootCertPath);//调用getRootCertSN获取支付宝根证书序列号


        $request = new \AlipayFundTransToaccountTransferRequest();
        $request->setBizContent("{" .
            "\"out_biz_no\":\"$order_no\"," .
            "\"payee_type\":\"ALIPAY_LOGONID\"," .
            "\"payee_account\":\"$account\"," .
            "\"amount\":\"$price\"," .
            "\"payer_show_name\":\"郑州微镖科技有限公司\"," .
            "\"payee_real_name\":\"$username\"," .
            "\"remark\":\"账户提现\"" .
            "}");
        $result = $aop->execute ( $request);
        Log::record($result);
        $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";

        $resultCode = $result->$responseNode->code;
        if(!empty($resultCode)&&$resultCode == 10000){
            return true;
        } else {
            throw new Exception($result->$responseNode->sub_msg);
        }
    }