Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use CloudPay.unifiedOrder () in Wechat Development

2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to use CloudPay.unifiedOrder () in Wechat development. I hope you will get something after reading this article. Let's discuss it together.

CloudPay.unifiedOrder ()

Supporting end: cloud function 2.0.2

WeChat Pay issued the order uniformly.

Description

Merchants first call this API in Mini Program to generate a prepaid transaction order at the backend of WeChat Pay service, return the correct prepaid transaction, and then adjust the payment.

Description of key parameters

Description of key parameters related to cloud development: callback function settings: envId and functionName are used to set the cloud function return field payment of asynchronous notification callback after receiving payment: this object is the information needed to call wx.requestPayment on Mini Program.

Callback Cloud function return Protocol

The cloud function of the payment result callback must return one of the following objects, otherwise the callback will be considered unsuccessful and the cloud function will receive a duplicate payment callback:

Field name variable name required type description

The error code errcode is Number0

Error message errmsg is String

Parameter description

Field name variable name required type sample value description

Result notification callback cloud function name functionName is the cloud function name for Stringpaycallback to receive WeChat Pay asynchronous notification callback

Result notification callback cloud function environment envId is the environment ID of the cloud function in which Stringtest-123 receives WeChat Pay asynchronous notification callback

Sub-merchant number subMchId is the sub-merchant number assigned by String (32) 1900000109 WeChat Pay

Device No. DeviceInfo No. String (32) 013467007045764 Terminal equipment No. (store number or cashier device ID). Note: for payment on PC web page or official account, please pass "WEB".

The random string nonceStr is a String (32) 5K8264ILTKCH16CQ2502SI8ZNMTM67VS random string that is no longer than 32 bits. Recommended random number generation algorithm

Commodity description body is a simple description of String (128) Tencent Voucher Center-QQ VIP recharged goods. This field must be delivered in strict accordance with the specifications. For more information, please see the parameters.

Product details detail No String (6000) detailed description of the product. For merchants using single product discount, this field must be uploaded in accordance with the specification. For more information, please see "description of single Product discount parameters".

Additional data attach No string (127) indicates additional data, which is returned as is in query API and payment notification. This field is mainly used for custom data of merchants carrying orders.

Merchant order number outTradeNo is String (32) 1217752501201407033233368018 internal order number of merchant system. It can only be numbers, uppercase and lowercase letters _-within 32 characters.

Currency Type No string (16) CNY A three-digit code that conforms to the ISO 4217 standard. The default is RMB: CNY. For more information on other values, please see currency types.

Total amount totalFee is the total amount of the Int888 order and can only be an integer. For more information, please see the payment amount.

Terminal IPspbillCreateIp is an IP address of String (64) 123.12.12.123 that supports both IPV4 and IPV6 formats. Call the machine IP of WeChat Pay API

Transaction start time timeStart No String (14) 20091225091010 order generation time in yyyyMMddHHmmss format, as indicated by 20091225091010 at 09:10:10 on December 25, 2009. For other details, see time rules.

The order expiration time is for the order number. Since there is a required parameter prepay_id with a validity period of only two hours when requesting payment, you need to re-request the API to issue an order to obtain a new prepay_id when the reentry time exceeds 2 hours. For other details, see the rules of time.

It is recommended that the minimum failure interval is more than 1 minute.

Transaction type tradeType is String (16) JSAPI. The values for Mini Program are as follows: JSAPI. For more information, please see the parameters.

Specify payment method payment No string (32) no_creditno_credit-- specifies that credit card payment cannot be used

User ID: whether OpenID is string (128C) oUpF8uMuAJO_M2pxb1Q9zNjWeS6otrade_type=JSAPI. This parameter is required. It is the unique identity of the user under the merchant appid. For more information on how to obtain openid, please see [obtain openid].

Openid and sub_openid can choose one of them. If you choose to pass sub_openid, you must pass sub_appid. Before placing an order, you need to call the API [Web Authorization to obtain user Information] to obtain the user's Openid.

You need to activate the electronic invoice function on WeChat Pay merchant platform or Wechat public platform before this field can take effect.

Scene information sceneInfo No string (256) Y this field is often used to report scene information during offline activities. It is supported to report actual store information, and merchants can also report relevant information on their own as needed. This field is JSON object data, and the 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 sample value description

Store idid No string (32) SZTX001 store number, customized by merchant

Store name No string (64) the name of Tengda Restaurant in Tencent Building is customized by merchants.

Store administrative division code area_code No String (6) 440305 administrative district code where the store is located. For more information, please see "the latest Administrative Division Code of County and above".

Store address address No string (128) detailed address of Tencent Building, one Road in Science and Technology Park, customized by merchants

Return value description

Field name variable name required type sample value description

The return status code returnCode is String (16) SUCCESSSUCCESS/FAIL. This field is the communication ID, not the transaction ID. You need to check result_code to determine whether the transaction is successful or not.

Return message SecretnMsg No string (128) failed to sign the message. If it is not empty, it is the reason for the error. Such as signature failure, parameter format verification error

The following fields are returned when returnCode is SUCCESS

Field name variable name required type sample value description

The information needed to initiate payment in Mini Program payment is the information needed by Object Mini Program to call wx.requestPayment

The APPIDappid of the service provider is the APPID of the merchant of String (32) wxd678efh667hg6787 service provider

Merchant number mch_id is the merchant number submitted by the calling API String (32) 1900000109

The APPIDsub_appid of Mini Program is the Mini Program ID assigned by String (32) wx8888888888888888 Wechat

Sub-merchant number sub_mch_id is the sub-merchant number assigned by String (32) 1900000109 WeChat Pay

Device number device_ in string (32) 013467007045764 the terminal device number submitted by calling the API

Random string nonce_str is a random string returned by String (32) 5K8264ILTKCH16CQ2502SI8ZNMTM67VS Wechat

Signature sign is the signature returned by String (64) C380BEC2BFD727A4B6845133519F3AD6 Wechat. For more information, please see signature algorithm.

Business result result_code is String (16) SUCCESSSUCCESS/FAIL

Error code err_ code No string (32) SYSTEMERROR see error list in section 6 for details

Error code description err_code_des No String (128) description of information returned by system error

The following fields are returned when both returnCode and result_code are SUCCESS

Field name variable name required type sample value description

Transaction type trade_type is the transaction type submitted by the String (16) JSAPI call API. The values are as follows: JSAPI. For more information, please see the parameters.

Prepaid transaction session ID prepay_id is a prepaid reply ID generated by String (64) wx201410272009395522657a690389285100 Wechat and used in subsequent API calls. This value is valid for 2 hours.

The QR code link code_ url string (64) weixin://wxpay/bizpayurl/up?pr=NwY5Mz9&groupid=00trade_type=NATIVE is returned sometimes. This url is used to generate the payment QR code, and then provide it to the user to scan the code for payment. Note: the value of code_url is not fixed. When you use it, you can convert it to a QR code according to URL format.

Error code

Name describes the cause solution

INVALID_REQUEST parameter error if the parameter format is incorrect or the order is not uploaded according to the rules, the parameter value is required to be the same as the original request. Please confirm the parameter problem.

NOAUTH merchants do not have this API permission. Merchants who do not have this API permission are invited to apply for this API permission.

Insufficient NOTENOUGH balance, insufficient user account balance, insufficient user account balance, please recharge or replace the payment card before paying.

ORDERPAID merchant order paid merchant order has been paid, no need to repeat operation merchant order has been paid, no more action is needed

ORDERCLOSED order closed the current order is closed, unable to pay the current order is closed, please reissue the order

SYSTEMERROR system error system timeout system exception, please call again with the same parameter

APPID_NOT_EXISTAPPID does not exist missing APPID in parameter check whether APPID is correct

MCHID_NOT_EXISTMCHID does not exist missing MCHID in parameter check whether MCHID is correct

APPID_MCHID_NOT_MATCHappid and mch_id do not match appid and mch_id do not match. Please make sure appid and mch_id match.

LACK_PARAMS missing parameters missing necessary request parameters please check whether the parameters are complete

SIGNERROR signature error parameter signature result is incorrect Please check whether the signature parameters and methods meet the requirements of the signature algorithm

XML_FORMAT_ERRORXML format error XML format error Please check whether the XML parameter format is correct

REQUIRE_POST_METHOD Please use post method instead of using post to pass parameters check whether the request parameters are submitted through the post method

POST_DATA_EMPTYpost data is empty post data cannot be empty Please check whether post data is empty

NOT_UTF8 encoding format error did not use the specified encoding format please use UTF-8 encoding format

Sample code

/ / Cloud function code

Const cloud = require ('wx-server-sdk')

Cloud.init ({

Env: cloud.DYNAMIC_CURRENT_ENV

})

Exports.main = async (event, context) = > {

Const res = await cloud.cloudPay.unifiedOrder ({

"body": "Xiaoqiu TIT Store-supermarket"

"outTradeNo": "1217752501201407033233368018"

"spbillCreateIp": "127.0.0.1"

"subMchId": "1900009231"

"totalFee": 1

"envId": "test-f0b102"

"functionName": "pay_cb"

})

Return res

}

/ / Mini Program Code

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 (res) {

Console.error ('pay fail', err)

}

})

}

Fail: console.error

})

After reading this article, I believe you have a certain understanding of "how to use CloudPay.unifiedOrder () in Wechat development". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report