function jsApiCall(data ,callback_succ_func ,callback_error_func){
//使用原生的,避免初始化appid问题
WeixinJSBridge.invoke('getBrandWCPayRequest', {
appId:data['appId'],
timeStamp: data['timeStamp'],
nonceStr: data['nonceStr'],
package: data['package'],
signType: data['signType'],
paySign: data['paySign'],
},
function(res) {
var msg = res.err_msg ?res.err_msg :res.errMsg;
//WeixinJSBridge.log(msg);
switch (msg) {
case 'get_brand_wcpay_request:ok': //支付成功时
if(callback_succ_func){
callback_succ_func(res);
}
break;
default: //支付失败时
WeixinJSBridge.log('支付失败!'+msg+',请返回重试.');
if(callback_error_func){
callback_error_func({msg:msg});
}
break;
}
})
}
//WeixinJSBridge判断
function wxJsPay(data ,callback_succ_func ,callback_error_func){
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', this.jsApiCall, false);
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', this.jsApiCall);
document.attachEvent('onWeixinJSBridgeReady', this.jsApiCall);
}
} else {
this.jsApiCall(data ,callback_succ_func ,callback_error_func);
}
}
//判断是否是微信内浏览器
function isWxBrowser(){
if(window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == "micromessenger"){
return true
}else{
return false
}
}

//暴露出接口列表
module.exports = {
jsApiCall:jsApiCall,
wxJsPay:wxJsPay,
isWxBrowser:isWxBrowser
}