123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- // 点击充值
- //充值地址
- var paystop = true;
- var payurl = '/api/recharge/pay';
- var args = {};
- $('.btn-pay').click(function(){
- args.goodsId = $(this).attr('data-goods_id');
- args.price = $(this).attr('data-price');
- args.actId = $(this).attr('data-act_id');
- args.subCode = $('#sub_code').val();
- // toastSuccess(data);exit;
- var pdata = {
- id: args.goodsId,
- activityId: 0,
- business_line:0,
- category: 'wechat',
- orderExtendType:2,//订阅活动
- actId:args.actId,
- subCode:args.subCode,
- };
- var acting = $('#acting').val();
- if ( acting == 1 ){
- $('#success_normal .apply').text('您已经报名');
- $('#success_normal .today').text('明日开始打卡,别忘记了来参加啊~');
- $('#success_normal').show();
- }else if(acting == 2){
- $('#success_normal .apply').text('您已经报名');
- $('#success_normal').show();
- }else if( acting == 3 ){
- $('#success_normal .apply').text('活动结束');
- $('#success_normal .today').text('');
- $('#success_normal').show();
- }else{
- gopay(pdata);
- }
- })
- // console.log(window.log_host)
- function gopay(pdata) {
- if ( !paystop ){
- return false;
- }
- paystop = false;
- $.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(22);
- alert(data.msg);
- }
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- paystop = true;
- alert(errorThrown);
- paystop = true;
- },
- complete: function () {
- $('.js_loading').hide();
- }
- })
- }
- /**
- * 微信公众号支付
- * @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.price,
- res: res
- }
- }, 'subscription']);
- 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.price,
- res: res
- }
- }, 'subscription']);
- 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.price,
- res: res
- }
- }, 'subscription']);
- 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.price,
- res: res
- }
- }, 'subscription']);
- }
- 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(){
- $('#success_normal .today').text('明日开始打卡,别忘记了来参加啊~');
- $('#success_normal').show();
- setTimeout(function(){
- $('#success_normal').hide();
- window.location.reload()
- },3000)
- }
|