Table 6-6 getBrandWCPayRequest return value
JS API return result get_brand_wcpay_request:ok is only returned when the user successfully completes the payment. Due to the complexity of front-end interaction, get_brand_wcpay_request:cancel
or
get_brand_wcpay_request:fail can be treated uniformly as the user encounters an error or gives up voluntarily, without making a detailed distinction.
2. JS API payment implementation
The following code is the JS API payment demo provided by WeChat official
<?php
include_once("WxPayHelper.php");
$commonUtil = new CommonUtil();
$wxPayHelper = new WxPayHelper();
$wxPayHelper->setParameter("bank_type", "WX");
$wxPayHelper->setParameter("body", "test");
$wxPayHelper->setParameter("partner", "1900000109");
$wxPayHelper->setParameter("out_trade_no", $commonUtil->create_noncestr());
$wxPayHelper->setParameter("total_fee", "1");
$wxPayHelper->setParameter("fee_type", "1");
$wxPayHelper->setParameter("notify_url", "htttp://www.baidu.com");
$wxPayHelper->setParameter("spbill_create_ip", "127.0.0.1");
$wxPayHelper->setParameter("input_charset", "GBK");
?>
<html>
<script language="javascript">
function callpay()
{
WeixinJSBridge.invoke('getBrandWCPayRequest',<?php echo $wxPayHelper->create_biz_package(); ?>,function(res){
WeixinJSBridge.log(res.err_msg);
alert(res.err_code+res.err_desc+res.err_msg);
});
}
</script>
<body>
<button type="button" onclick="callpay()">wx pay test</button>
</body>
</html>
Modify the WeChat payment parameters into Get what you applied for, then upload the webpage to the WeChat payment directory, and reply the webpage address to the test account. Users can implement a JS API payment.
3. Effect Demonstration
The following is the page picture of initiating payment after the official DEMO has been modified.

Confirm transaction

Enter payment password

Transaction successful

For more articles related to WeChat payment development JS API payment, please pay attention to the PHP Chinese website!