Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat applet getPaidUnionId


May 19, 2021 WeChat Mini Program Development Document


Table of contents


auth.getPaidUnionId

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.

  • Note: The user is required to complete the payment before the call and is valid for five minutes after payment.

How to call:

  • HTTPS call
  • Cloud calls

HTTPS call

The request address

GET https://api.weixin.qq.com/wxa/getpaidunionid?access_token=ACCESS_TOKEN&openid=OPENID

Request parameters

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

Returns a value

Object

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

Instructions for use

Choose between the following two options.

  1. WeChat payment order number (transaction_id):
https://api.weixin.qq.com/wxa/getpaidunionid?access_token=ACCESS_TOKEN&openid=OPENID&transaction_id=TRANSACTION_ID
  1. WeChat payment merchant order number and WeChat payment merchant (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 an example of the data

{
  "unionid": "oTmHYjg-tElZ68xxxxxxxxhy1Rgk",
  "errcode": 0,
  "errmsg": "ok"
}

Cloud calls

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.

The interface method

openapi.auth.getPaidUnionId
Permissions for the auth.getPaidUnionId API need to be configured in config.json, details

Request parameters

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

Returns a value

Object

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

Abnormal

Object

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

An example of a request

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
  }
}

Return an example of the data

{
  "unionid": "oTmHYjg-tElZ68xxxxxxxxhy1Rgk",
  "errCode": 0,
  "errMsg": "openapi.auth.getPaidUnionId:ok"
}