目录
官方信息:
1.下载SDK
根据自身的需要选择SDK包
下载之后放在了 vendor 文件下:
2.业务层
支付宝证书模式下的配置参考跳转:https://mp.csdn.net/mp_blog/creation/success/127964188
array2string(array_reverse($ssl['issuer'])) . $ssl['serialNumber']); return $SN; } public function getRootCertSN($certPath) { $cert = file_get_contents($certPath); // $this->alipayRootCertContent = $cert; $array = explode("-----END CERTIFICATE-----", $cert); $SN = null; for ($i = 0; $i < count($array) - 1; $i++) { $ssl[$i] = openssl_x509_parse($array[$i] . "-----END CERTIFICATE-----"); if (strpos($ssl[$i]['serialNumber'], '0x') === 0) { $ssl[$i]['serialNumber'] = $this->hex2dec($ssl[$i]['serialNumberHex']); } if ($ssl[$i]['signatureTypeLN'] == "sha1WithRSAEncryption" || $ssl[$i]['signatureTypeLN'] == "sha256WithRSAEncryption") { if ($SN == null) { $SN = md5($this->array2string(array_reverse($ssl[$i]['issuer'])) . $ssl[$i]['serialNumber']); } else { $SN = $SN . "_" . md5($this->array2string(array_reverse($ssl[$i]['issuer'])) . $ssl[$i]['serialNumber']); } } } return $SN; } function hex2dec($hex) { $dec = 0; $len = strlen($hex); for ($i = 1; $i <= $len; $i++) { $dec = bcadd($dec, bcmul(strval(hexdec($hex[$i - 1])), bcpow('16', strval($len - $i)))); } return $dec; } protected function array2string($array) { $string = []; if ($array && is_array($array)) { foreach ($array as $key => $value) { $string[] = $key . '=' . $value; } } return implode(',', $string); }}
3.业务层返回实例
返回的和APP支付文档上不一样哦,这里返回的是一串请求字符串,我们给前端客户端去请求支付宝
可以参考官方文档:APP 支付快速接入 | 网页&移动应用
"alipay_root_cert_sn=6***支付宝根路径证书提取的序列号&alipay_sdk=alipay-sdk-php-2020-04-15&app_cert_sn=证书序列号&app_id=2021*****&biz_content=%7B%22total_amount%22%3A%220.01%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%2C%22subject%22%3A%22%5Cu6d4b%5Cu8bd5%5Cu5546%5Cu54c1%22%2C%22out_trade_no%22%3A1672109672%7D&charset=utf-8&format=json&method=alipay.trade.app.pay¬ify_url=****&sign_type=RSA2×tamp=2022-12-27+10%3A54%3A32&version=1.0&sign=sign"
推荐使用联调工具:
https://opensupport.alipay.com/support/tools/cloudparse/interface?ant_source=antsupport
4.回调层
public function appPayNotify() { // 打个日志看看 $sFileName = 'alipay.txt'; $sContent = date('Y-m-d H:i:s') . '开始回调\r\n' . '\r\n'; file_put_contents($sFileName, $sContent, FILE_APPEND); // 回调参数根据文档上的异步回调通知看看自己需要的参数接收用 POST 接收过来就行 $notifyTime = $_POST['notify_time']; // 回调时间 $notifyType = $_POST['notify_type']; // 通知类型 $notifyId = $_POST['notify_id']; // 通知检验 ID $appId = $_POST['app_id']; // 支付宝分配给开发者的应用 APPID $authAppId = $_POST['auth_app_id']; // 开发者的 app_id,在服务商调用的场景下为授权方的 app_id $tradeNo = $_POST['trade_no']; // 支付宝交易凭证号 $orderNo = $_POST['out_trade_no']; // 原支付请求的商家订单号 // 打个日志看看 $sFileName = 'alipay.txt'; $sContent = date("Y-m-d H:i:s") . '接收到_POST方式回调参数\r\n' . json_encode($orderNo, JSON_UNESCAPED_UNICODE) . '\r\n'; file_put_contents($sFileName, $sContent, FILE_APPEND); // 接收到回调之后输出 success 给支付宝 echo 'success'; die; }
绑定方法之后使用APP 自带的 uni.requestPayment方法来发起
// 购买执行async actionRpBuy() {if (this.num == '' || this.num == 0) {uni.showToast({title: '请选择购买数量',icon: 'none'});return false;}request({url: '/请求地址',}).then(res => {if (res.code == 1) {console.log(res.data);uni.requestPayment({ provider: 'alipay', //'alipay','wxpay'// manifest.json->APP模块配种->payment配置一下 orderInfo:res.data, // 这个参数给后端返回的请求字符串 success: res => { uni.navigateTo({ url: '../CompletionOfPayment/CompletionOfPayment' }) }, fail: err => { let orderId = this.ids uni.showModal({ // title: '提示', title: err, content: '支付失败', success: function(res) { if (res.confirm) {} else if (res.cancel) {} } }) } })}})},
内容尽量写的仔细一点所以文章有点长,感谢阅读
来源地址:https://blog.csdn.net/arlene12345/article/details/128478362