123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- var qs = parseQueryString(window.location.href),token,rechargeMoney = 0,goodsId,user_id,order_id;
- $().ready(function(){
- if(qs.order_id){
- order_id = qs.order_id;
- $(".wx_payment_mask").show();
- }
- getTokenAddUserIdEvent()
- wxPaymentResult();
- })
- function app_h5_getOrderId (data) {//支付是否成功,解ios微信白页bug
- if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
- if(data){
- var dataes = JSON.parse(data)
- order_id = dataes.order_id
- $(".wx_payment_mask").show();
- // window.location.href="./paymentResult.html?type=3&order_id=" + order_id
- }
- }
- }
- function getTokenAddUserIdEvent () {
- //获取token 和 user_id
- var param = '{"js_callback" : "getTokenAddUserId"}';
- try{
- if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
- window.webkit.messageHandlers.app_h5_getTokenAndUserid.postMessage(param);
- }
- if(navigator.userAgent.match(/android/i)){
- obj4H5.app_h5_getTokenAndUserid(param);
- }
- }catch(e){
- console.log("兼容")
- // token = 'c1c63ee904336d416627ac09c85fa5cb'
- // user_id = '10'
- // rechargeListData()
- }
- }
- function getTokenAddUserId (data) {//app token 回调
- var dataes = JSON.parse(data)
- token = dataes.token;
- user_id = dataes.user_id;
- rechargeListData()
- }
- function rechargeListData () {
- //充值套餐列表--
- $(".loading").show();
- $.ajax({
- type: 'get',
- url: '/user/rechargeList',
- data:{
- user_id:user_id
- },
- headers:{
- token: token
- },
- success: function (res) {
- $(".loading").hide();
- console.log(res)
- if(res.errno == 200){
- var rechargeListHtml = '',recharge_type_html;
- res.rst.forEach(function (item,index) {
- //recharge_type": 0, //套餐类型 1--首充套餐 2--一般套餐',
- recharge_type_html = '',free_gold_html = '';
- //free_gold充值是否送金币 0的时候不送
- if(item.recharge_type == 1){
- recharge_type_html = '<img src="img/payment_one.png"/>'
- }
- if(item.free_gold != 0){
- free_gold_html = '<span>送' + item.free_gold + '江湖币</span>'
- }
- rechargeListHtml += '<li onclick="packageSelection(' + item.id + ',' + item.money + ')"><div class="rechargeLi rechargeLi_' + item.id + '"><p>充' + item.recharge_gold + '江湖币</p>' + free_gold_html + recharge_type_html + '</div></li>'
- });
- $(".rechargeList").html(rechargeListHtml)
- }else{
- showMsg(res.rst.msg)
- }
- },
- error: function () {
- showMsg('请稍后再试~')
- $(".loading").hide();
- }
- })
- }
- function payEvent () {
- //立即支付按钮事件
- var type = $(".payment_mode li input[name='mode']:checked").val();//1为支付宝 2为微信
- if(!goodsId){
- showMsg('请选择您需要的套餐')
- return;
- }
- if(!type){
- showMsg('请选择您的支付方式')
- return;
- }
- window.location.href = '/credit/pay?goods_id=' + goodsId + '&pay_type=' + type + '&user_id=' + user_id
- }
- function wxPaymentResult () {
- //微信支付结果
- $("#paySuccess").on('click',function () {
- console.log('支付成功')
- wxCheckOrder();
- $(".wx_payment_mask").hide();
- })
- $("#payError").on('click',function () {
- console.log('支付失败')
- wxCheckOrder();
- $(".wx_payment_mask").hide();
- })
- }
- function wxCheckOrder () {
- //查询订单是否支付成功
- $(".loading").show();
- $.ajax({
- url:'/user/wx_check_order',
- type:'post',
- dataType:'json',
- data:{
- client:1,
- order_id:order_id
- },
- success: function (res){
- $(".loading").hide();
- if(res && res.errno == 0){
- showMsg('恭喜您,订单支付成功!')
- }else{
- showMsg('订单支付失败,请重新支付!')
- }
- },
- error: function (err){
- $(".loading").hide();
- }
- })
- }
- function packageSelection (goods_id,money){
- //套餐选择事件
- goodsId = goods_id;
- rechargeMoney = money;
- $(".payment_bottom .total span").html('¥' + rechargeMoney)
- $(".rechargeLi").removeClass('rechargeLiActive')
- $(".rechargeLi_" + goods_id).addClass('rechargeLiActive')
- }
- //获取地址栏参数
- function parseQueryString(url) {
- var urlObj = {};
- var reg = /([^?=&]+)=([^?=&]+)/g;
- url.replace(reg, function($0, $1, $2) {
- urlObj[$1] = decodeURIComponent($2);
- })
- return urlObj;
- }
- // 展示错误提示信息
- function showMsg(msg) {
- var msgBox = document.getElementsByClassName('alert-info')[0];
- msgBox.getElementsByTagName("p")[0].innerHTML=msg;
- msgBox.style.display="block";
-
- setTimeout(function() {
- msgBox.style.display="none";
-
- }, 2000);
- }
|