# auth.getPaidUnionId
Call this API at the server side. For more information, see Server API.
This API supports Cloud Calls. The WeChat DevTools version must be
1.02.1904090
or later (download the latest stable version here), and thewx-server-sdk
version must be0.4.0
or later.
Obtains the UnionId of a user after the user completes payment, without needing user authorization. This API supports Query on Third-Party Platform Agents.
- Note: The API needs to be called after the user completes payment, and takes effect within five minutes after the payment.
Calling methods:
# HTTPS Call
# Request Address
GET https://api.weixin.qq.com/wxa/getpaidunionid?access_token=ACCESS_TOKEN&openid=OPENID
# Request Parameters
Attribute | Type | Default | Required | Description |
---|---|---|---|---|
access_token | string | Yes | Credentials to call API | |
openid | string | Yes | The unique identifier of the WeChat Pay user | |
transaction_id | string | No | WeChat Pay Order Number | |
mch_id | string | No | Merchant ID assigned by WeChat Pay. It is used with the merchant order number. | |
out_trade_no | string | No | WeChat Pay Merchant Order Number. It is used with the merchant ID. |
# Return Value
# Object
JSON data package that is returned
Property | Type | Description |
---|---|---|
unionid | string | The unique identifier of the user. It is returned when the call succeeds. |
errcode | number | Error code |
errmsg | string | Error message |
Valid values of errcode
Value | Description | Minimum Version |
---|---|---|
-1 | System is busy. Try again later. | |
0 | Request successful | |
40003 | Incorrect openid | |
89002 | No bound WeChat Open Platform account | |
89300 | Invalid order |
# How to Use
Use either of the following methods:
- WeChat Pay order number (transaction_id):
https://api.weixin.qq.com/wxa/getpaidunionid?access_token=ACCESS_TOKEN&openid=OPENID&transaction_id=TRANSACTION_ID
- WeChat Pay merchant order number and WeChat Pay merchant ID (out_trade_no and mch_id):
https://api.weixin.qq.com/wxa/getpaidunionid?access_token=ACCESS_TOKEN&openid=OPENID&mch_id=MCH_ID&out_trade_no=OUT_TRADE_NO
# Return Data Example
{
"unionid": "oTmHYjg-tElZ68xxxxxxxxhy1Rgk",
"errcode": 0,
"errmsg": "ok"
}
# Cloud Call
Cloud call is a capability provided by Mini Program·Cloud Base that allows you to call WeChat APIs in a cloud function. It must be used via
wx-server-sdk
in the cloud function.
# API Calling Method
openapi.auth.getPaidUnionId
You need to configure the permissions for the
auth.getPaidUnionId
API viaconfig.json
. Details
# Request Parameters
Attribute | Type | Default | Required | Description |
---|---|---|---|---|
openid | string | Yes | The unique identifier of the WeChat Pay user | |
transactionId | string | No | WeChat Pay Order Number | |
mchId | string | No | Merchant ID assigned by WeChat Pay. It is used with the merchant order number. | |
outTradeNo | string | No | WeChat Pay Merchant Order Number. It is used with the merchant ID. |
# Return Value
# Object
JSON data package that is returned
Attribute | Type | Description |
---|---|---|
unionid | string | The unique identifier of the user. It is returned when the call succeeds. |
errCode | number | Error code |
errMsg | string | Error message |
Valid values of errCode
Value | Description | Minimum Version |
---|---|---|
0 | Succeeded |
# Exceptions
# Object
Thrown Exceptions
Property | Type | Description |
---|---|---|
errCode | number | Error code |
errMsg | string | Error message |
Valid values of errCode
Value | Description | Minimum Version |
---|---|---|
-1 | System is busy. Try again later. | |
40003 | Incorrect openid | |
89002 | No bound WeChat Open Platform account | |
89300 | Invalid order |
# Request Example
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: ''
})
console.log(result)
return result
} catch (err) {
console.log(err)
return err
}
}
# Return Data Example
{
"unionid": "oTmHYjg-tElZ68xxxxxxxxhy1Rgk",
"errCode": 0,
"errMsg": "openapi.auth.getPaidUnionId:ok"
}