123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- // 点击充值
- //充值地址
- var paystop = true;
- var payurl = '/api/recharge/pay';
- var args = {};
- $('.now_btn_chongzhi').click(function(){
- args.userKandian = $('.userKandian').val();
- args.cotegoryId = $('.userKandian').attr('good_cotegory');
- args.activeId = $(".count_item_active div .kandian").attr('data-id');
- args.matchDate = $(".count_item_active div .kandian").attr('data-date');
- args.matchId = $(".count_item_active div .kandian").attr('data-match');
- args.goodsId = $(".count_item_active div .kandian").attr('data-goods');
- args.kandian = $(".count_item_active div .kandian").text();
- args.money = $(".count_item_active div .kandian").attr('data-money');
- args.readNumber = $('.userKandian').attr('read_number');
- if ( !paystop ){
- return false;
- }
- paystop = false;
- // toastSuccess(data);exit;
- var pdata = {
- id: args.goodsId,
- activityId: 0,
- business_line:0,
- category: 'wechat',
- orderExtendType:1,
- campKandian:args.kandian,
- campMatchDate:args.matchDate,
- };
- $.ajax({
- url: payurl,
- data: pdata,
- type: 'POST',
- timeout: 35000,
- success: function (data) {
- paystop = true;
- if (data.code) {
- switch (pdata.business_line) {
- case 0: //微信公众号支付
- if (data.data) {
- var oJsonObj = JSON.parse(data.data.json);
- wechatPay(oJsonObj, pdata.goodsId);
- } else {
- consoleMain(data.msg);
- }
- break;
- default: //alipay 支付宝 //wechath5 微信H5支付
- break;
- }
- } else {
- alert(data.msg);
- }
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- cpslog([703, {
- map: {
- xdtype: args.cotegoryId,
- result: 4,
- book_id: 0,
- adid: args.goodsId,
- chapter_id: 0,
- business:0,
- money: args.money,
- XMLHttpRequest: XMLHttpRequest.status,
- textStatus: textStatus,
- errorThrown: errorThrown
- }
- }, 'campaign']);
- paystop = true;
- alert('异常错误,请刷新页面重试');
- paystop = true;
- },
- complete: function () {
- $('.js_loading').hide();
- }
- })
- })
- // console.log(window.log_host)
- /**
- * 微信公众号支付
- * @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) {
- args.money = $(".count_item_active div .kandian").attr('data-money');
- 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: 0,
- chapter_id: 0,
- money: args.money,
- res: res
- }
- }, 'campaign']);
- toastChecking();
- break;
- case 'get_brand_wcpay_request:cancel': //取消
- // consoleMain('您已取消充值');
- wechatCancel(goodsId);
- cpslog([703, {
- map: {
- cztype: 'wechat',
- package: json.package,
- result: 2,
- book_id: 0,
- chapter_id: 0,
- money: args.money,
- res: res
- }
- }, 'campaign']);
- break;
- case 'get_brand_wcpay_request:fail': //失败
- consoleMain('充值失败,请尝试重新充值或试试其他充值方式');
- wechatCancel(goodsId);
- cpslog([703, {
- map: {
- cztype: 'wechat',
- package: json.package,
- result: 3,
- book_id: 0,
- chapter_id: 0,
- money: args.money,
- res: res
- }
- }, 'campaign']);
- break;
- default:
- 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: 0,
- chapter_id: 0,
- money: args.money,
- res: res
- }
- }, 'campaign']);
- }
- break;
- }
- }
- );
- }
- //endregion
- function wechatCancel(goodsId) {
- $.ajax({
- url: '/api/recharge/wechatCancel',
- data: {
- url: window.location.href,
- goods_id: goodsId
- },
- type: 'POST',
- timeout: 10000,
- success: function (data) {
- },
- error: function (err) {
- }
- })
- }
- //充值成功后显示报名中,3s 消失
- function toastChecking(){
- $('.amount_null').show();
- setTimeout(function(){
- $('.amount_null').hide();
- window.location.reload()
- },3000)
- }
|