var smoney = ''; var sbookid = commont.getQueryString('book_id', window.location.search, '&') || ''; var schapterid = commont.getQueryString('chapter_id', window.location.search, '&') || ''; var toUrl = $('#tourl').val(); $(function () { $('.show_pay_close').click(function(){ $('.show_pay_box').hide(); }); $(document).on('click','.select_pay',function(){ $('input[name="payment_id"]').removeAttr("checked"); $(this).find('input[name="payment_id"]').prop("checked", 'checked'); }); $('.re_but_box a').click(function () { $('.show_pay_box').show(); }); /** * 充值按钮 */ var paystop = true; $(document).on('click','.pay_btn',function(){ if (!paystop) { return false } paystop = false; var $this = $(this), goodsId = $this.data('goods-id'), goodsaId = $this.data('goods-aid'), goodsCategory = $this.data('goods-category'); smoney = $this.data('money'); business_line = parseInt($this.data('business_line')); payment_id = $('input[name="payment_id"]:checked').val(); cpslog([702, { adid: goodsId, map: { book_id: sbookid, chapter_id: schapterid, money: smoney } }, business_line]); var data = { id: goodsId, aid:goodsaId, business: business_line, payment:payment_id, category: goodsCategory }; $('.js_loading').show(); $.ajax({ url: '/clientwebapi/recharge/pay', data: data, type: 'POST', timeout: 35000, success: function (data) { paystop = true; console.log(data); if (data.code) { switch (business_line) { case 1: //微信公众号支付 if (data.data) { if(data.data.callback !== undefined){ eval(data.data.callback); } cpslog([703, { map: { package: oJsonObj.package, xdtype: goodsCategory, result: 1, book_id: sbookid, adid: goodsId, chapter_id: schapterid, business: business_line, money: smoney } }, 'xdjg']); } else { consoleMain(data.msg); } break; default: //alipay 支付宝 //wechath5 微信H5支付 break; } } else { consoleMain(data.msg); cpslog([703, { map: { xdtype: goodsCategory, result: 2, book_id: sbookid, adid: goodsId, chapter_id: schapterid, business: business_line, money: smoney } }, 'xdjg']); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { consoleMain('异常错误,请刷新页面重试'); cpslog([703, { map: { xdtype: goodsCategory, result: 4, book_id: sbookid, adid: goodsId, chapter_id: schapterid, business: business_line, money: smoney, XMLHttpRequest: XMLHttpRequest.status, textStatus: textStatus, errorThrown: errorThrown } }, 'xdjg']); paystop = true; }, complete: function () { $('.js_loading').hide(); } }) }); /** * 处理默认充值商品自动下单 */ var check = $('.re_but_box a.check'); if(check.length){ check.click(); } }); /** * 微信公众号支付 * @param json 微信支付相关数据 * @param goodsId 商品id */ function wechatPay(json, goodsId) { if (typeof WeixinJSBridge == "undefined") { if (document.addEventListener) { document.addEventListener('WeixinJSBridgeReady', function () { onBridgeReady(json, goodsId); }, false); } else if (document.attachEvent) { document.attachEvent('WeixinJSBridgeReady', function () { onBridgeReady(json, goodsId); }); document.attachEvent('onWeixinJSBridgeReady', function () { onBridgeReady(json, goodsId); }); } } else { onBridgeReady(json, goodsId); } } /** * 微信内唤起充值窗口 * @param json * @param goodsId */ function onBridgeReady(json, goodsId) { WeixinJSBridge.invoke( 'getBrandWCPayRequest', json, function (res) { switch (res.err_msg) { case 'get_brand_wcpay_request:ok': //成功 consoleMain('充值成功'); cpslog([703, { map: { cztype: 'wechat', package: json.package, result: 1, book_id: sbookid, chapter_id: schapterid, money: smoney, res: res } }, 'czjg']); if (toUrl) { //回跳到最近阅读页 window.location.href = toUrl; }else{ setTimeout(function () { window.location.reload(true); },1000); } break; case 'get_brand_wcpay_request:cancel': //取消 consoleMain('您已取消充值'); wechatCancel(goodsId); cpslog([703, { map: { cztype: 'wechat', package: json.package, result: 2, book_id: sbookid, chapter_id: schapterid, money: smoney, res: res } }, 'czjg']); break; case 'get_brand_wcpay_request:fail': //失败 consoleMain('充值失败,请尝试重新充值或试试其他充值方式'); wechatCancel(goodsId); cpslog([703, { map: { cztype: 'wechat', package: json.package, result: 3, book_id: sbookid, chapter_id: schapterid, money: smoney, res: res } }, 'czjg']); break; default: console.log(res); wechatCancel(goodsId); if (typeof res.err_msg == 'undefined' && res.errMsg == 'chooseWXPay:fail, the permission value is offline verifying') { consoleMain('充值失败,原因:模拟器无法充值'); } else { consoleMain('异常错误,请刷新页面重试'); cpslog([703, { map: { cztype: 'wechat', package: json.package, result: 4, book_id: sbookid, chapter_id: schapterid, money: smoney, res: res } }, 'czjg']); } break; } } ); } function wechatCancel(goodsId) { }