🧾 WeChat mini program/H5 to adjust the confirmation and collection interface (with code + platform compatibility processing)
Scenario: After the user clicks the "Cash Collection" button, the system will call up the WeChat collection component, and the user will complete the transfer or collection process after confirmation. This capability is widely used in business scenarios such as cash marketing, second-hand transactions, commission remuneration, and corporate compensation.
See the official documentation for details
💡 Background
WeChat official updated in the first two monthsrequestMerchantTransferInterface, allowWeChat appletandH5 pageRelease a user to confirm the payment and the user can complete the transfer after completing the confirmation.
This API can be used to implement:
- When the merchant makes payment to the user, please confirm (the platform sends it on behalf of the user)
- The user confirms the receipt to another user (point-to-point receipt)
- Wallet withdrawal application (display transfer details first → User consent → Initiate payment)
...
⚙️Precautions for use
✅ Application requirements:
- Need to open a WeChat payment merchant platformMerchant transfers to changeProduct permissions;
- Bind to a mini program or official account;
- Need to set up
mchId
(Merchant number),appId
(The appid of the current mini program/public account),package
(Order details package).
🔄 Call method:
platform | Instructions for calling |
---|---|
Mini Program | Native API
|
H5 in WeChat | pass() Call |
See also official documentation for the APP, including Android and iOS, no detailed description here
🔧 Core code implementation
The following uses uniapp as a compatible mini program + the complete call method of WeChat H5 on both ends (you can use it after copying):
getMoney(item) {
const that = this;
// The judgment platform can also be used (// #ifdef MP-WEIXIN // #endif)
if ( === 'wx') {
// ✅ Mini-program call method
({
mchId: , // Merchant number, generated and issued by WeChat Pay
appId: , // The AppID bound by the merchant (corpid number corpid is this AppID), generated by WeChat, and can be viewed in the background of the official account
package: item.package_info, // corresponding package_info in the response parameter of the initiating transfer interface (returned only when the transfer document status is WAIT_USER_CONFIRM: is confirmed by the user), which is used to invoke the user to confirm the receipt page.
success(res) {
('User confirms that the payment is successful', res);
({
title: 'The collection was successful',
icon: 'success'
});
(false, 1); // Refresh data
},
fail(res) {
('User confirmation failed to receive payment', res);
({
title: 'Cash failed',
icon: 'error'
});
},
complete(res) {
('Request completed', res);
}
});
} else if ( === 'h5') { // It can also be used (// #ifdef H5 // #endif)
// ✅ H5 calling method (make sure it is in the WeChat environment)
(function() {
({
jsApiList: ['requestMerchantTransfer'],
success: function(res) {
if (['requestMerchantTransfer']) {
// The H5 end is called through WeixinJSBridge
('requestMerchantTransfer', {
mchId: ,
appId: ,
package: item.package_info,
}, function(res) {
if (res.err_msg === 'requestMerchantTransfer:ok') {
({
title: 'The collection was successful',
icon: 'success'
});
(); // Refresh data
} else {
('User cancellation or payment failed', res);
}
});
} else {
alert('Your WeChat version is too low, please update to the latest version.');
}
}
});
});
}
}
🔍 Interpretation (key points description)
Parameters/logic | Meaning/Description |
---|---|
mchId |
Merchant number under WeChat Merchant Platform |
appId |
AppID of mini program or official account |
package |
Details of payment returned by WeChat payment platform (encrypted) |
|
The built-in API for mini-program terminal is to initiate the transfer confirmation process |
() |
The JS bridge call on the H5 end of WeChat is used to invoke payment, collection and other interfaces |
checkJsApi() |
Check whether the current WeChat version supports the JS API |
err_msg: ok |
It means that the user confirms the receipt before the success logic will be executed. |
⚠️ FAQ & Tips for Trapping
- Please make sure that the transfer permissions are configured in the applet, otherwise it will report "no permission";
-
The H5 call must be in
()
and the JS-SDK signature is injected first; - The WeChat version is lower than 7.0.20 and may not support this capability;
- Please do not test the H5 side in non-WeChat browsers, WeixinJSBridge cannot be injected;
- The package parameters must be obtained from the backend, and be sure to pay attention to encryption and signature verification.;
📚 Reference link:
WeChat open document: requestMerchantTransfer