tp对接支付宝转账提现
支付宝流程
tp对接支付宝转账提现
咱们开始
第一步 下载demo
请自行注册开发者账号。
- 进入支付宝开放平台,文档中心》APP支付》下载SDK&Demo,放到tp框架的Vendor中
4.配置文件
在tp框架中配置接入支付宝需要的配置的参数
//支付宝 支付配置'ALI_CONFIG' => array('gatewayUrl' => 'https://openapi.alipay.com/gateway.do',//支付宝网关(固定)''appId' => 'appIDappIDappIDappIDappIDappIDappID',//APPID即创建应用后生成//由开发者自己生成: 请填写开发者私钥去头去尾去回车,一行字符串'rsaPrivateKey' => 'AfewqFEWfefedwfewfewfewfewfewfewfwefewfewfeefwef',//支付宝公钥,由支付宝生成: 请填写支付宝公钥,一行字符串'alipayrsaPublicKey' => 'ewqdwqfwqdfwqfwqfwqfqwfwqfwqfwqfwqfwqferagrGERW',)
- 控制器代码
1.支付宝提现 需要用到公钥证书,涉及到提现的公钥证书是必须要的
2. 公钥证书定义为项目根路径
//支付宝转账提现到个人支付宝public function alitransfer(){$param = $this->request->param();$orderinfo = $this->WithdrawalOrder->where('id',$param['id'])->find();if ($orderinfo == null){return false;}require_once root_path() .'/vendor/Alipay/aop/AopCertClient.php';require_once root_path() .'/vendor/Alipay/aop/request/AlipayFundTransUniTransferRequest.php';$aop = new \AopCertClient();$appCertPath = "/data/alipay/appCertPublicKey.crt";//应用证书路径(要确保证书文件可读),例如:/home/admin/cert/appCertPublicKey.crt$alipayCertPath = "/data/alipay/alipayCertPublicKey_RSA2.crt";//支付宝公钥证书路径(要确保证书文件可读),例如:/home/admin/cert/alipayCertPublicKey_RSA2.crt$rootCertPath = "/data/alipay/alipayRootCert.crt";//支付宝根证书路径(要确.$aliConfig = Config('app.ALI_CONFIG'); //加载配置项$aop->gatewayUrl = $aliConfig['gatewayUrl'];$aop->appId = $aliConfig['appId'];$aop->rsaPrivateKey = $aliConfig['rsaPrivateKey'];$aop->format = "json";$aop->charset= "utf-8";$aop->signType= "RSA2";//调用getPublicKey从支付宝公钥证书中提取公钥$aop->alipayrsaPublicKey = $aop->getPublicKey($alipayCertPath);//是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内$aop->isCheckAlipayPublicCert = true;//调用getCertSN获取证书序列号$aop->appCertSN = $aop->getCertSN($appCertPath);//调用getRootCertSN获取支付宝根证书序列号$aop->alipayRootCertSN = '687b59193f3f462dd5336e5abf83c5d8_02941eef3187dddf3d3b83462e1dfcf6';
// $res = $aop->getRootCertSN($rootCertPath);$request = new \AlipayFundTransUniTransferRequest ();if ($orderinfo['type']==2){ //如果是实名认证提现$request->setBizContent("{" ."\"out_biz_no\":\"$orderinfo[order_no]\"," ."\"trans_amount\":$orderinfo[money]," ."\"product_code\":\"TRANS_ACCOUNT_NO_PWD\"," ."\"biz_scene\":\"DIRECT_TRANSFER\"," ."\"payee_info\":{" ."\"identity\":\"$orderinfo[alipay_id]\"," ."\"identity_type\":\"ALIPAY_USER_ID\"," .
// "\"name\":\"$orderinfo[money]\"," ." }," ."\"remark\":\"账户提现\"," ." }");}if ($orderinfo['type']==3){ //手机号提现$request->setBizContent("{" ."\"out_biz_no\":\"$orderinfo[order_no]\"," ."\"trans_amount\":$orderinfo[money]," ."\"product_code\":\"TRANS_ACCOUNT_NO_PWD\"," ."\"biz_scene\":\"DIRECT_TRANSFER\"," ."\"payee_info\":{" ."\"identity\":\"$orderinfo[alipay_tel]\"," ."\"identity_type\":\"ALIPAY_LOGON_ID\"," ."\"name\":\"$orderinfo[name]\"," ." }," ."\"remark\":\"账户提现\"," ." }");}$result = $aop->execute ( $request);$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";$resultCode = $result->$responseNode->code;if(!empty($resultCode)&&$resultCode == 10000){//修改订单状态return success_msg('提现成功');} else {//修改订单状态return error_msg('提现失败');}}
- 码字不易,求点赞
- 如果任何侵权行为请联系管理员删除