May 19, 2021 WeChat Mini Program Development Document
This interface should be called on the server side, as detailed in the Service Side API.
This interface supports cloud calls. Developer tool version required . . . 1.02.1904090 (latest stable download)
wx-server-sdk >= 0.4.0
After the user pays, obtain the user's UnionId without user authorization. This interface supports third-party platform proxy queries.
How to call:
GET https://api.weixin.qq.com/wxa/getpaidunionid?access_token=ACCESS_TOKEN&openid=OPENID
Property | Type | The default | Required | Description |
---|---|---|---|---|
access_token | string | Is | The interface calls the credentials | |
Openid | string | Is | Pay the user's unique identity | |
transaction_id | string | Whether | WeChat pays for the order number | |
mch_id | string | Whether | WeChat pays for the assigned merchant number, which is used in conjunction with the merchant order number | |
out_trade_no | string | Whether | WeChat pays the merchant order number, which is used in conjunction with the merchant number |
The returned JSON packet
Property | Type | Description |
---|---|---|
unionid | string | The user is uniquely identified and returns after the call is successful |
errcode | number | Error code |
errmsg | string | The error message |
The legal value of errcode
Value | Description | The lowest version |
---|---|---|
-1 | The system is busy, so please try again later | |
0 | The request was successful | |
40003 | Openid error | |
89002 | Open platform accounts are not bound | |
89300 | The order is not valid |
Choose between the following two options.
https://api.weixin.qq.com/wxa/getpaidunionid?access_token=ACCESS_TOKEN&openid=OPENID&transaction_id=TRANSACTION_ID
https://api.weixin.qq.com/wxa/getpaidunionid?access_token=ACCESS_TOKEN&openid=OPENID&mch_id=MCH_ID&out_trade_no=OUT_TRADE_NO
{
"unionid": "oTmHYjg-tElZ68xxxxxxxxhy1Rgk",
"errcode": 0,
"errmsg": "ok"
}
Cloud calling is the ability provided by the small program Cloud Development to invoke WeChat's open interface in cloud functions and needs to be used in cloud functions via wx-server-sdk.
openapi.auth.getPaidUnionId
Permissions for the auth.getPaidUnionId API need to be configured in config.json, details
Property | Type | The default | Required | Description |
---|---|---|---|---|
Openid | string | Is | Pay the user's unique identity | |
transactionId | string | Whether | WeChat pays for the order number | |
mchId | string | Whether | WeChat pays for the assigned merchant number, which is used in conjunction with the merchant order number | |
outTradeNo | string | Whether | WeChat pays the merchant order number, which is used in conjunction with the merchant number |
The returned JSON packet
Property | Type | Description |
---|---|---|
unionid | string | The user is uniquely identified and returns after the call is successful |
errCode | number | Error code |
errMsg | string | The error message |
The legal value of errCode
Value | Description | The lowest version |
---|---|---|
0 | Success |
The exception thrown
Property | Type | Description |
---|---|---|
errCode | number | Error code |
errMsg | string | The error message |
The legal value of errCode
Value | Description | The lowest version |
---|---|---|
-1 | The system is busy, so please try again later | |
40003 | Openid error | |
89002 | Open platform accounts are not bound | |
89300 | The order is not valid |
const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
try {
const result = await cloud.openapi.auth.getPaidUnionId({
openid: '',
transactionId: '',
mchId: '',
outTradeNo: ''
})
return result
} catch (err) {
return err
}
}
{
"unionid": "oTmHYjg-tElZ68xxxxxxxxhy1Rgk",
"errCode": 0,
"errMsg": "openapi.auth.getPaidUnionId:ok"
}