From 94044074b10eb660dd5766f73aeafb707f80e91b Mon Sep 17 00:00:00 2001 From: yanyilin Date: Mon, 17 Jan 2022 20:13:52 +0800 Subject: [PATCH] update app-payment-weixin.md --- docs/app-payment-weixin.md | 165 +++++++++++++++++++++---------------- 1 file changed, 96 insertions(+), 69 deletions(-) diff --git a/docs/app-payment-weixin.md b/docs/app-payment-weixin.md index 220fb1a1a..82565d2b1 100644 --- a/docs/app-payment-weixin.md +++ b/docs/app-payment-weixin.md @@ -1,91 +1,118 @@ -#### 开通 -* 登录[微信开放平台](https://open.weixin.qq.com/),申请移动应用并开通支付功能,申请应用后可以获取 AppID -* 应用接入[微信商户平台](https://pay.weixin.qq.com/index.php/core/home/login?return_url=%2F),选择 App 支付 -* 开通支付功能后可获取支付业务服务器配置数据:PARTNER(财付通商户号)、PARTNER_KEY(财付通密钥)、PAYSIGNKEY(支付签名密钥) -更多信息详见[移动应用开发](https://open.weixin.qq.com/cgi-bin/frame?t=home/app_tmpl&lang=zh_CN) +### 开通 +- 登录[微信开放平台](https://open.weixin.qq.com/),添加移动应用并提交审核,审核通过后可获取应用ID(AppID,支付订单中需要使用) +- 在应用详情中`申请开通`微信支付功能,根据页面提示填写资料,提交审核 +- 支付申请审核通过后将收到邮件,包括`商户号`(PartnerID,支付订单中需要使用)和`登录密码` +- 使用`商户号`和`登录密码`登录[微信商户平台](https://pay.weixin.qq.com/index.php/core/home/login),进入 “账户中心” > “API安全” > “设置APIv2密钥” 设置API密钥(用于服务器生成订单),详情参考[API证书及密钥](https://kf.qq.com/faq/180830UVRZR7180830Ij6ZZz.html) + +更多信息详见微信官方文档 [APP支付接入申请流程指引](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/WeChat_Pay/Vendor_Service_Center.html),服务器接入相关信息详见 [APP支付接入前准备](https://pay.weixin.qq.com/wiki/doc/apiv3/open/pay/chapter2_5_1.shtml) + -#### 配置 +### 配置 在manifest.json文件“App模块配置”项的“Payment(支付)”下,勾选“微信支付”项 ![](https://partner-dcloud-native.oss-cn-hangzhou.aliyuncs.com/images/uniapp/payment/wxpay_setup_manifest_info.png) -* appid填写'开通'中的应用AppID -* 通用链接参考[生成iOS通用链接](https://uniapp.dcloud.io/api/plugins/universal-links) + +**参数说明** +- appid +微信开放平台申请的应用ID(AppID) +- iOS平台通用链接(Universal Link) +在iOS平台微信支付使用的通用链接,必须与微信开放平台 “管理中心” > “应用详情” > “开发信息” 中的“Universal Links”项中配置一致,更多详情参考 [一键生成iOS通用链接](https://uniapp.dcloud.io/api/plugins/universal-links) + -#### 服务器生成订单 -通过服务器生成支付订单,参考:[微信支付示例(PHP)](https://github.com/dcloudio/H5P.Server/tree/master/payment/wxpayv3) +### 服务器生成订单 +在 App 端调用支付前,需在业务服务器生成支付订单,可参考: +- [微信支付示例(PHP)](https://github.com/dcloudio/H5P.Server/tree/master/payment/wxpayv3) + +更多信息详见微信支付官方文档 [APP支付统一下单](https://opendocs.alipay.com/open/204/01dcc0) + -#### 应用内发起支付 -订单信息参数如下 +### 应用内发起支付 + +- uni-app项目 +调用 [uni.requestPayment(OBJECT)](https://uniapp.dcloud.io/api/plugins/payment?id=requestpayment) 发起支付,OBJECT参数中provider属性值固定为`wxpay`、orderInfo属性值为订单对象 +- 5+ App项目 +调用 [plus.payment.request(channel, orderInfo, successCB, errorCB)](https://www.html5plus.org/doc/zh_cn/payment.html#plus.payment.request) 发起支付, channel参数为微信支付对象,orderInfo参数为订单对象 -| 参数名称 | 参数说明 | 必须 | -|-------------|-------|-----| -| appid | 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致 | 是 | -| noncestr | 随机字符串 | 是 | -| package | 固定值 |是 | -| partnerid | 微信支付商户号 | 是 | -| prepayid | 统一下单订单号 | 是 | -| timestamp | 时间戳(单位:秒) | 是 | -| sign | 签名,这里用的 MD5 签名 | 是 | - * uni-app项目示例(provider填写wxpay) +##### 订单对象参数说明 +Object对象类型 + +| 属性 | 类型 | 必填 | 说明 | +| :--- | :--- | :--- | :--- | +| appid | String | 是 | 应用ID(AppID),请登录[微信开放平台](https://open.weixin.qq.com/)查看,注意与公众号的APPID不同 | +| partnerid | String | 是 | 微信支付分配的商户号(PartnerID)| +| prepayid | String | 是 | 预支付交易会话ID | +| package | String | 是 | 扩展字段,固定值"Sign=WXPay" | +| noncestr | String | 是 | 随机字符串,不长于32位 | +| timestamp | String | 是 | 时间戳,标准北京时间,时区为东八区,自1970年1月1日 0点0分0秒以来的秒数 | +| sign | String | 是 | 签名,详见[签名生成算法](https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=4_3) | + +更多信息详见微信支付官方文档 [APP支付调起支付接口](https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_12&index=2) + + +#### 示例代码 +- uni-app项目 ``` js +//订单对象,从服务器获取 +var orderInfo = { + "appid": "wx499********7c70e", // 应用ID(AppID) + "partnerid": "148*****52", // 商户号(PartnerID) + "prepayid": "wx202254********************fbe90000", // 预支付交易会话ID + "package": "Sign=WXPay", // 固定值 + "noncestr": "c5sEwbaNPiXAF3iv", // 随机字符串 + "timestamp": 1597935292, // 时间戳(单位:秒) + "sign": "A842B45937F6EFF60DEC7A2EAA52D5A0" // 签名,这里用的 MD5 签名 +}; uni.getProvider({ - service: 'payment', - success: function (res) { - console.log(res.provider) - if (~res.provider.indexOf('wxpay')) { - uni.requestPayment({ - "provider": "wxpay", - "orderInfo": { - "appid": "wx499********7c70e", // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致 - "noncestr": "c5sEwbaNPiXAF3iv", // 随机字符串 - "package": "Sign=WXPay", // 固定值 - "partnerid": "148*****52", // 微信支付商户号 - "prepayid": "wx202254********************fbe90000", // 统一下单订单号 - "timestamp": 1597935292, // 时间戳(单位:秒) - "sign": "A842B45937F6EFF60DEC7A2EAA52D5A0" // 签名,这里用的 MD5 签名 - }, - success: function (res) { - var rawdata = JSON.parse(res.rawdata); - console.log("支付成功"); - }, - fail: function (err) { - console.log('支付失败:' + JSON.stringify(err)); - } - }) - } - } + service: 'payment', + success: function (res) { + console.log(res.provider) + if (~res.provider.indexOf('wxpay')) { + uni.requestPayment({ + "provider": "wxpay", //固定值为"wxpay" + "orderInfo": orderInfo, + success: function (res) { + var rawdata = JSON.parse(res.rawdata); + console.log("支付成功"); + }, + fail: function (err) { + console.log('支付失败:' + JSON.stringify(err)); + } + }); + } + } }); ``` - * 5+App项目示例 +- 5+ App项目 ``` js - //获取支付渠道 - var wxpaySev = null; - plus.payment.getChannels(function(channels) { - for (var i in channels) { - var channel = channels[i]; - if (channel.id === 'wxpay') { +//订单对象,从服务器获取 +var orderInfo = { + "appid": "wx499********7c70e", // 应用ID(AppID) + "partnerid": "148*****52", // 商户号(PartnerID) + "prepayid": "wx202254********************fbe90000", // 预支付交易会话ID + "package": "Sign=WXPay", // 固定值 + "noncestr": "c5sEwbaNPiXAF3iv", // 随机字符串 + "timestamp": 1597935292, // 时间戳(单位:秒) + "sign": "A842B45937F6EFF60DEC7A2EAA52D5A0" // 签名,这里用的 MD5 签名 +}; +//获取支付渠道 +var wxpaySev = null; +plus.payment.getChannels(function(channels){ + for (var i in channels) { + var channel = channels[i]; + if (channel.id === 'wxpay') { wxpaySev = channel; - } - } - }, function(e) { - console.log("获取支付渠道失败:" + e.message); - }); + } + } //发起支付 - var statement = { - "appid": "wx499********7c70e", // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致 - "noncestr": "c5sEwbaNPiXAF3iv", // 随机字符串 - "package": "Sign=WXPay", // 固定值 - "partnerid": "148*****52", // 微信支付商户号 - "prepayid": "wx202254********************fbe90000", // 统一下单订单号 - "timestamp": 1597935292, // 时间戳(单位:秒) - "sign": "A842B45937F6EFF60DEC7A2EAA52D5A0" // 签名,这里用的 MD5 签名 - }; - plus.payment.request(wxpaySev, statement, function(result) { + plus.payment.request(wxpaySev, orderInfo, function(result) { var rawdata = JSON.parse(result.rawdata); console.log("支付成功"); }, function(e) { console.log("支付失败:" + e.message); }); + }, function(e){ + console.log("获取支付渠道失败:" + e.message); +}); ``` -- GitLab