Skip to main content
Wechat Jsapi Process
This payment method must be initiated inside the WeChat in-app browser.
It will NOT work in external browsers such as Chrome or Safari.

Overview

WeChat JSAPI enables payments inside an Official Account web page viewed within WeChat. This method is ideal for:
  • Official Account H5 stores
  • In-app service flows
  • QR campaigns opening inside WeChat
For merchants in Canada, refer to
/docs/online-shop/alipay/alipay-web-payments
where pay_type = 800207.

Integration Methods

Method 1 — Merchant’s Own Official Account

Merchants use their verified WeChat Official Account. Requirements
  1. Official Account verified & linked to QFPay
  2. Obtain user openid
  3. Domain added to JSAPI whitelist
Resources:

Method 2 — QFPay Official Account (Indirect Settlement)

For merchants without a verified account, QFPay provides an Official Account.

Payment Flow Overview

  1. User opens payment page inside WeChat
  2. Retrieve OAuth code
  3. Exchange code → obtain openid
  4. Submit payment request
  5. Redirect to WeChat JSAPI payment module
  6. Verify payment result via backend

Step 1 — Obtain WeChat OAuth Code

Request GET /tool/v1/get_weixin_oauth_code
This endpoint must be opened inside WeChat.
app_code and sign must be sent as query parameters, not headers.

Parameters

NameParamRequiredDescription
App Codeapp_codeYesProvided by QFPay
Redirect URLredirect_uriYesURL after authorization
Merchant IDmchidNoProvided if applicable
SignaturesignYesMD5 signature using client_key
def make_req_sign(data, key):
    keys = sorted(data.keys())
    raw = "&".join(f"{k}={data[k]}" for k in keys) + key
    return hashlib.md5(raw.encode()).hexdigest().upper()
Response
{
  "redirect": "https://yourdomain.com/callback?code=011xxxxx"
}
Redirect the user to the returned URL.

Step 2 — Exchange Code for openid

Request GET /tool/v1/get_weixin_openid

Parameters

ParameterRequiredDescription
codeYesOAuth code from Step 1
mchidNoRequired for some merchants
Headers required:
  • X-QF-APPCODE
  • X-QF-SIGN
def get_open_id(code):
    params = {"code": code}
    headers = {
        "X-QF-APPCODE": app_code,
        "X-QF-SIGN": make_req_sign(params, client_key)
    }
    r = requests.get(environment + "/tool/v1/get_weixin_openid",
                     params=params, headers=headers)
    return r.json().get("openid")
Response
{
  "respcd": "0000",
  "openid": "oo3Lss8d0hLOuyTuSJMVwLTk68JE"
}
A new OAuth code and openid must be obtained for each payment attempt.
Do not cache or reuse.

Step 3 — Submit Payment Request

Endpoint POST /trade/v1/payment PayType: 800207 (WeChat JSAPI)

Required Fields

FieldRequiredDescription
sub_openidYesopenid from Step 2
Common ParametersYesamount, currency, timestamp, order no
limit_payNorestrict payment methods
extend_infoNoreal-name verification (Mainland China only)
Refer to:
def create_payment(openid):
    data = {
        "txamt": "100",
        "txcurrcd": "HKD",
        "pay_type": "800207",
        "out_trade_no": "ORDER12345",
        "txdtm": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
        "sub_openid": openid
    }
    headers = {
        "X-QF-APPCODE": app_code,
        "X-QF-SIGN": make_req_sign(data, client_key)
    }
    r = requests.post(environment + "/trade/v1/payment",
                      params=data, headers=headers)
    return r.json()["pay_params"]

pay_params Response

FieldDescription
appIdOfficial Account AppID
timeStamptimestamp
nonceStrrandom string
packageprepay package
signTypesignature method
paySignpayment signature

Step 4 — Redirect to WeChat Payment Module

Redirect the user’s browser to: GET https://o2-hk.qfapi.com/q/direct

Required Parameters

ParameterDescription
mchntnmMerchant display name
txamtAmount
currencyCurrency
redirect_urlURL after payment
packagefrom pay_params
timeStampfrom pay_params
signTypefrom pay_params
paySignfrom pay_params
appIdfrom pay_params
nonceStrfrom pay_params
This request is sent directly from the user’s browser.
No authentication headers are required.

Additional Notes

  • JSAPI flow must be executed sequentially
  • Do not reuse OAuth codes or openid
  • If payment result is delayed, verify via
    Transaction Enquiry API
  • Real-name verification is optional and depends on merchant configuration