当前位置:网站首页>Wechat applet payment
Wechat applet payment
2022-07-21 19:54:00 【Meta universe iwemeta】
CloudPay.unifiedOrder()
Support end : Cloud functions 2.0.2
Unified order
explain
The merchant calls the interface in the applet to generate the pre payment transaction list in the background of wechat payment service , Return the correct prepaid transaction and raise the payment .
This interface is the same as the original interface of wechat payment ( file ) The difference is :
- Private secure link , Certificate free management , Signature free calculation
- Merchant number filled in sub_mch_id Field , Applet / official account appid fill sub_appid Field
- Do not fill in the following fields :mch_id、appid、sign、sign_type
- Interface input and return values are JSON instead of XML
Key parameter description
Cloud development related The key parameters explain :
- Callback function settings :
envId
andfunctionName
Cloud function used to set the asynchronous notification callback after receiving payment - Return field
payment
: This object is called on the applet sidewx.requestPayment
Required information
Input and return protocol of the cloud function receiving payment result callback
See Payment result callback cloud function Protocol .
Parameter description
Field name | Variable name | Required | type | Example value | describe |
---|---|---|---|---|---|
Result notification callback cloud function name | functionName | yes | String | paycallback | The name of the cloud function that receives the asynchronous notification callback of wechat payment |
Result notification callback cloud function environment | envId | yes | String | test-123 | The environment of the cloud function that receives the asynchronous notification callback of wechat payment ID |
Sub merchant No | subMchId | yes | String(32) | 1900000109 | The sub merchant number assigned by wechat payment |
Device number | deviceInfo | no | String(32) | 013467007045764 | Terminal equipment number ( Store number or cashier equipment ID), Be careful :PC Please send it to the website or official account for payment "WEB" |
Random string | nonceStr | yes | String(32) | 5K8264ILTKCH16CQ2502SI8ZNMTM67VS | Random string , Not longer than 32 position . recommend Random number generation algorithm |
Commodity Description | body | yes | String(128) | Tencent recharge Center -QQ Member recharge | Brief description of goods , This field must be passed in strict accordance with the specification , Please refer to Parameter specification |
Goods details | detail | no | String(6000) | Product description , For the merchants who use the item discount , This field must be uploaded according to the specification , See “ Item discount parameter description ” | |
Additional data | attach | no | String(127) | explain | Additional data , In the query API And payment notice original sample return , This field is mainly used for custom data of orders carried by merchants |
Merchant order number | outTradeNo | yes | String(32) | 1217752501201407033233368018 | Internal order number of merchant system , requirement 32 Within a character , It's just numbers 、 Case letters _- |
Type of currency | feeType | no | String(16) | CNY | accord with ISO 4217 Standard three letter code , Default RMB :CNY, For a list of other values, see Type of currency |
Total sum | totalFee | yes | Int | 888 | Total order amount , It can only be an integer , See Pay the amount |
terminal IP | spbillCreateIp | yes | String(64) | 123.12.12.123 | Support IPV4 and IPV6 Two formats of IP Address . Call wechat payment API Machine IP |
Transaction start time | timeStart | no | String(14) | 20091225091010 | Order generation time , The format is yyyyMMddHHmmss, Such as 2009 year 12 month 25 Japan 9 spot 10 branch 10 Seconds are expressed as 20091225091010. For others, see Rules of time |
The closing time of the transaction | timeExpire | no | String(14) | 20091227091010 | Order expiration time , The format is yyyyMMddHHmmss, Such as 2009 year 12 month 27 Japan 9 spot 10 branch 10 Seconds are expressed as 20091227091010. The order expiration time is for the order number , Because there is a required parameter when requesting payment prepay_id It's only valid for two hours , So in reentry time more than 2 You need to re request the order interface to get new prepay_id. For others, see Rules of time . Suggest : The minimum failure time interval is greater than 1 minute |
Order discount mark | goodsTag | no | String(32) | WXG | Order discount mark , Parameters of voucher or discount function , Detailed description Voucher or discount |
Type of transaction | tradeType | yes | String(16) | JSAPI | The value of the applet is as follows :JSAPI, For details, see Parameter specification |
Specify the method of payment | limitPay | no | String(32) | no_credit | no_credit-- Specify that credit cards cannot be used for payment |
User ID | openid | no | String(128) | oUpF8uMuAJO_M2pxb1Q9zNjWeS6o | trade_type=JSAPI, This parameter must be passed , The user is in the merchant appid Unique identification under .openid How to get , May refer to 【 obtain openid】. |
User identification | subOpenid | no | String(128) | oUpF8uMuAJO_M2pxb1Q9zNjWeS6o | trade_type=JSAPI, This parameter must be passed , The user is at the sub merchant appid Unique identification under .openid and sub_openid You can choose one of them , If you choose to pass sub_openid, You have to pass it on sub_appid. You need to call before placing an order 【 Web page authorization to get user information 】 Interface to get the user's Openid. |
E-invoice entrance opening logo | receipt | no | String(8) | Y | Y, Pass in Y when , The billing entry will appear on the payment success message and payment details page . You need to open the electronic invoice function on wechat payment merchant platform or wechat public platform , This field will take effect |
Scene information | sceneInfo | no | String(256) | Y | This field is often used to report scene information during offline activities , Support reporting actual store information , Merchants can also report relevant information on their own . That field is JSON Object data , Object format is {"store_info":{"id": " store ID","name": " name ","area_code": " code ","address": " Address " }} |
sceneInfo.storeInfo Object description *
Field name | Variable name | Required | type | Example value | describe |
---|---|---|---|---|---|
store id | id | no | String(32) | SZTX001 | Store number , Customized by merchants |
Store name | name | no | String(64) | Tencent building Tengda restaurant | Store name , Customized by merchants |
Store administrative division code | area_code | no | String(6) | 440305 | The administrative division code of the store , Detailed see 《 The latest administrative division code of county and above 》 |
Store detailed address | address | no | String(128) | Tencent building, Zhongyi Road, science and Technology Park | Store detailed address , Customized by merchants |
Return value description
Field name | Variable name | Required | type | Example value | describe |
---|---|---|---|---|---|
Return status code | returnCode | yes | String(16) | SUCCESS | SUCCESS/FAIL This field is the communication ID , Non transaction identification , Whether the transaction is successful or not needs to be checked result_code To judge |
Return information | returnMsg | no | String(128) | Signature failed | Return information , If not empty , For the wrong reason . Such as Signature failed 、 Parameter format validation error |
The following fields are in the returnCode by SUCCESS When you come back
Field name | Variable name | Required | type | Example value | describe |
---|---|---|---|---|---|
The information needed to initiate payment in the applet | payment | yes | Object | Applet side call wx.requestPayment Information needed | |
The service provider APPID | appid | yes | String(32) | wxd678efh567hg6787 | Of service providers and merchants APPID |
Merchant number | mch_id | yes | String(32) | 1900000109 | Merchant number submitted by calling interface |
Applet APPID | sub_appid | yes | String(32) | wx8888888888888888 | Wechat distribution applet ID |
Sub merchant No | sub_mch_id | yes | String(32) | 1900000109 | The sub merchant number assigned by wechat payment |
Device number | device_info | no | String(32) | 013467007045764 | The terminal device number submitted by the calling interface , |
Random string | nonce_str | yes | String(32) | 5K8264ILTKCH16CQ2502SI8ZNMTM67VS | The random string returned by wechat |
Signature | sign | yes | String(64) | C380BEC2BFD727A4B6845133519F3AD6 | Signature returned by wechat , See Signature algorithm |
Business results | result_code | yes | String(16) | SUCCESS | SUCCESS/FAIL |
Error code | err_code | no | String(32) | SYSTEMERROR | See page for details 6 Section error list |
Error code description | err_code_des | no | String(128) | System error | Description of the information returned by the error |
The following fields are in the returnCode and result_code All for SUCCESS When you come back
Field name | Variable name | Required | type | Example value | describe |
---|---|---|---|---|---|
Type of transaction | trade_type | yes | String(16) | JSAPI | The transaction type submitted by the calling interface , The values are as follows :JSAPI, For details, see Parameter specification |
Prepaid transaction session ID | prepay_id | yes | String(64) | wx201410272009395522657a690389285100 | Pre payment reply ID generated by wechat , Used in subsequent interface calls , The value is valid for 2 Hours |
Error code
name | describe | reason | Solution |
---|---|---|---|
INVALID_REQUEST | Parameter error | Parameter format is wrong or not uploaded according to the rules | On order re-entry , The parameter value is required to be consistent with the original request , Please confirm the parameter problem |
NOAUTH | Merchant does not have this interface permission | The merchant has not opened this interface authority | Please go to apply for the permission of this interface |
NOTENOUGH | Lack of balance | Insufficient balance of user account | Insufficient balance of user account , Please recharge or change the payment card before paying |
ORDERPAID | Merchant order paid | Merchant order paid , No need to repeat | Merchant order paid , No more action required |
ORDERCLOSED | Order closed | Current order closed , Unable to pay | Current order closed , Please re order |
SYSTEMERROR | System error | System timeout | System exception , Please call again with the same parameters |
APPID_NOT_EXIST | APPID non-existent | Missing in parameter APPID | Please check APPID Whether it is right |
MCHID_NOT_EXIST | MCHID non-existent | Missing in parameter MCHID | Please check MCHID Whether it is right |
APPID_MCHID_NOT_MATCH | appid and mch_id Mismatch | appid and mch_id Mismatch | Please make sure the appid and mch_id match |
LACK_PARAMS | Lack of parameter | Missing required request parameters | Please check whether the parameters are complete |
OUT_TRADE_NO_USED | Duplicate merchant order number | The same transaction cannot be submitted more than once | Please check if the order number of the merchant is submitted repeatedly |
SIGNERROR | Signature error | Incorrect parameter signature result | Please check whether the signature parameters and methods meet the requirements of the signature algorithm |
XML_FORMAT_ERROR | XML Format error | XML Format error | Please check XML Whether the parameter format is correct |
REQUIRE_POST_METHOD | Please use post Method | not used post Pass parameters | Please check if the request parameters pass post Method submission |
POST_DATA_EMPTY | post Data is empty | post Data cannot be empty | Please check post Is the data empty |
NOT_UTF8 | Wrong encoding format | The specified encoding format is not used | Please use UTF-8 Coding format |
Sample code
// 1、 Cloud function code , initialization
const cloud = require('wx-server-sdk')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})
//2、 Unified order
exports.main = async (event, context) => {
const res = await cloud.cloudPay.unifiedOrder({
"body" : " Autumn TIT shop - The supermarket ",
"outTradeNo" : "1217752501201407033233368018",
"spbillCreateIp" : "127.0.0.1",
"subMchId" : "1900009231",
"totalFee" : 1,
"envId": "test-f0b102",
"functionName": "pay_cb"
})
return res
}
// 3、 Applet payment ( Applet code ) , And judge the payment result
wx.cloud.callFunction({
name: ' Function name ',
data: {
// ...
},
success: res => {
const payment = res.result.payment
wx.requestPayment({
...payment,
success (res) {
console.log('pay success', res)
},
fail (err) {
console.error('pay fail', err)
}
})
},
fail: console.error,
})
边栏推荐
- Attack and defense world ----- favorite_ number
- 我的UI自动化测试的感悟
- 测试入门——使用场景法设计ATM的测试用例
- 【To .NET】. Net core web API development process knowledge points sorting [advanced]
- NXP i.MX 8M Mini 开发板规格参数,四核ARM Cortex-A53 + ARM Cortex-M4
- Content with element type "resultmap" must match "(constructor?, id*, result*, association*, collection*, discriminato?) “
- STM32——定位模块ATGM336H,数据解析,提取经纬度
- The ability to detect movement in vivo and build a safe and reliable payment level "face brushing" experience
- My understanding of UI automated testing
- The ability to detect movement in vivo and build a safe and reliable payment level "face brushing" experience
猜你喜欢
STM32——ADC读取光敏传感器控制LED灯,看门狗中断
【To .NET】. Net core web API development process knowledge points sorting [advanced]
Importerror: DLL load failed while importing win32gui: the specified module cannot be found.
STM32 - ADC reads the photosensitive sensor, controls the LED light, and the watchdog interrupts
Poste technique | a40i les trois problèmes de logiciel de carte réseau les plus courants, analysez - les un par un pour vous
MATLAB 自然样条函数(Spline,非MATLAB内置函数)
Machine learning sklearn dataset
Electromagnetic field and electromagnetic wave experiment II familiar with the application of MATLAB PDETOOL in two-dimensional electromagnetic problems
数据中台、BI业务访谈(二):组织架构梳理的坑
Ftxui basic notes (checkbox component)
随机推荐
如何确定你访问的网站的真实性——证书体系
Assertion failed: inputs.at(2).is_weights
2022.7.21DAY611
CV (4)- Backpropagation and Neural Networks
Iwemeta: Shi Yuzhu's golden sauce wine: OEM factories have been shut down. Who is producing it?
[C exercise] macro realizes the exchange of digital binary parity bits
"New product release" B2B connector version NXP i.MX 8m Mini industrial core board
45. Record the training process of orienmask and the process of deploying Yunshi technology depth camera
Unity ECS 测试Demo
元宇宙iwemeta:风口上的脑机接口,偷偷的解密大脑
【transformer】ViT
Introduction to testing -- using scenario method to design ATM test cases
获取ip地址
2022DASCTF MAY web
[C language] detailed explanation of file related functions
ES6的数组、对象拷贝
ctfshow MengXIn misc1
input: dynamic input is missing dimensions in profile
Ens reading notes
NR modulation 4-AM