1.微信支付中靜默調起支付:必須等到微信js加載完成,所以用下面注釋的方式不對。
<script type="text/javascript">
var $appid='${nativeMap.appId}';
var $timeStamp='${nativeMap.timeStamp}';
var $nonceStr='${nativeMap.nonceStr}';
var $package= '${nativeMap.Package}';
var $paySign='${nativeMap.paySign}';
function callpay(){
WeixinJSBridge.invoke('getBrandWCPayRequest',{
"appId" :$appid,
"timeStamp" :$timeStamp,
"nonceStr" : $nonceStr,
"package" : $package,
"signType" : "MD5",
"paySign" : $paySign
},function(res){
WeixinJSBridge.log(res.err_msg);
if(res.err_msg == "get_brand_wcpay_request:ok"){
//成功之后執行代碼
}else{
//失敗之后執行代碼
}
});
}
document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
callpay();
// 通過下面這個API隱藏右上角按鈕
//WeixinJSBridge.call('hideOptionMenu');
// 發送給好友
}, false);
/*
$(function(){
callpay();
}); */
</script>
2.支付鏈接必須在微信配置里面設置,在設置的目錄下面才能支付成功,下面有顏色的部分和微信哪里設置配置一致
try {
// 用戶授權頁面跳轉
String appid = WXConfig.PARAMETERS.APPID;
String redirect_url = basepath+"/pay/api/wxpay/"
+ oid + "?showwxpaytitle=1";
redirect_url = URLEncoder.encode(redirect_url, "UTF-8");
System.out.println(redirect_url);
System.out
.println(String
.format("https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base#wechat_redirect",
appid, redirect_url));
response.sendRedirect(String
.format("https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base#wechat_redirect",
appid, redirect_url));
} catch (IOException e) {
e.printStackTrace();
}