|
@@ -4,124 +4,219 @@ import './helper/response';
|
|
|
import Api from './helper/const';
|
|
|
import Utils from './helper/utils';
|
|
|
|
|
|
-const channel = Utils.GetQueryString('channel');
|
|
|
-const uid = Utils.GetQueryString('uid');
|
|
|
-let payWay = 'wx';
|
|
|
-let productId = '';
|
|
|
|
|
|
-const getStatus = (orderId) => {
|
|
|
-
|
|
|
+let wxPay = false;
|
|
|
+let aliPay = false;
|
|
|
+
|
|
|
+
|
|
|
+const getSignAjax = (mobile) => {
|
|
|
$.ajax({
|
|
|
- url: Api.composeApiPath(`order/${orderId}`),
|
|
|
+ url: Api.composeApiPath(`msg?mobileNo=${mobile}`),
|
|
|
dataType: "json",
|
|
|
async: true,
|
|
|
- headers: {
|
|
|
- uid: uid
|
|
|
- },
|
|
|
type: "GET",
|
|
|
success: function (res) {
|
|
|
- $.removeCookie('orderId');
|
|
|
- $.removeCookie('isPayBack');
|
|
|
- if ($.cookie('isWx')) {
|
|
|
- $.removeCookie('isWx');
|
|
|
- $('.buy-dialog').css('display', 'none')
|
|
|
- }
|
|
|
- if (res.data.status === 2) {
|
|
|
- console.log('支付成功')
|
|
|
- system.postMessage('success')
|
|
|
- } else {
|
|
|
- console.log('支付失败')
|
|
|
- system.postMessage('close')
|
|
|
- }
|
|
|
+ console.log(res);
|
|
|
+ alert('验证码已发送!')
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
-$('.wx-choose').addClass('choose');
|
|
|
|
|
|
+const regTest = (n) => {
|
|
|
+ const zhengze = /^[1]([3-9])[0-9]{9}$/;
|
|
|
+ if (zhengze.test(n)) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+let count = 60;
|
|
|
+const renderTimer = () => {
|
|
|
+ let timer = setTimeout(() => {
|
|
|
+ count--;
|
|
|
+ $('#sign_btn').html(`${count}秒后重新发送`)
|
|
|
+ if (count <= 0) {
|
|
|
+ $('#sign_btn').html(`发送验证码`)
|
|
|
+ count = 60;
|
|
|
+ clearTimeout(timer)
|
|
|
+ } else {
|
|
|
+ renderTimer()
|
|
|
+ }
|
|
|
+ }, 1000)
|
|
|
+}
|
|
|
|
|
|
-
|
|
|
+const getSign = () => {
|
|
|
+ if (count < 60 && count > 0) {
|
|
|
+ alert(`请在${count}秒后重新获取`)
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ renderTimer()
|
|
|
+ console.log('获取验证码')
|
|
|
+ console.log(document.getElementById('mobile_number').value)
|
|
|
+ let mobileNumber = document.getElementById('mobile_number').value;
|
|
|
|
|
|
-
|
|
|
-const changePayWay = (flag) => {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (flag === 'wx' && payWay !== 'wx') {
|
|
|
- payWay = 'wx';
|
|
|
- $('.zfb-choose').removeClass('choose');
|
|
|
- $('.wx-choose').addClass('choose');
|
|
|
+ if (regTest(mobileNumber)) {
|
|
|
+ getSignAjax(mobileNumber)
|
|
|
+ } else {
|
|
|
+ alert('手机号不规则')
|
|
|
}
|
|
|
- if (flag === 'zfb' && payWay !== 'zfb') {
|
|
|
- payWay = 'zfb';
|
|
|
- $('.wx-choose').removeClass('choose');
|
|
|
- $('.zfb-choose').addClass('choose');
|
|
|
+}
|
|
|
+
|
|
|
+const showDialog = (type, text1, text2) => {
|
|
|
+ if (type === 'bad') {
|
|
|
+ $('.success').css('display', 'none');
|
|
|
}
|
|
|
+ $('.pay_type').html(text1);
|
|
|
+ $('.pay_type_s').html(text2);
|
|
|
+ $('.buy-dialog').css('display', 'block')
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
-const createOrder = (method, id) => {
|
|
|
- let str = method === 'zfb' ? '/aliPay/prePay' : '/wxPay/prePay';
|
|
|
+const onBridgeReady = (data) => {
|
|
|
+ WeixinJSBridge.invoke(
|
|
|
+ 'getBrandWCPayRequest',
|
|
|
+ data,
|
|
|
+ function (res) {
|
|
|
+ if (res.err_msg == "get_brand_wcpay_request:ok") {
|
|
|
+
|
|
|
+
|
|
|
+ showDialog('success', '支付成功', '您已完成支付');
|
|
|
+ setTimeout(() => {
|
|
|
+ window.location.href = 'http://ott80-web.ai160.com/otttest/efunbox_xyyf/res/h5pay/about.html'
|
|
|
+ }, 1000)
|
|
|
+ return;
|
|
|
+
|
|
|
+ }
|
|
|
+ if (res.err_msg == "get_brand_wcpay_request:cancel" || res.err_msg == "get_brand_wcpay_request: fail") {
|
|
|
+ showDialog('bad', '支付失败', '请重新支付');
|
|
|
+ setTimeout(() => {
|
|
|
+ window.location.href = 'http://ott80-web.ai160.com/otttest/efunbox_xyyf/res/h5pay/about.html'
|
|
|
+ }, 2000)
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+const postBuyInfo = (mobile, sign, payType) => {
|
|
|
$.ajax({
|
|
|
- url: Api.composeApiPath(str),
|
|
|
+ url: Api.composeApiPath('order'),
|
|
|
dataType: "json",
|
|
|
async: true,
|
|
|
data: JSON.stringify({
|
|
|
- "channel": channel,
|
|
|
- "productId": id
|
|
|
+ "mobileNo": mobile,
|
|
|
+ "authorizeCode": Utils.GetQueryString('code'),
|
|
|
+ "identifyCode": sign,
|
|
|
+ "productId": 101001,
|
|
|
+ "payType": payType
|
|
|
}),
|
|
|
type: "POST",
|
|
|
- headers: {
|
|
|
- uid: uid
|
|
|
- },
|
|
|
contentType: "application/json",
|
|
|
- success: res => {
|
|
|
- $.cookie('orderId', res.data.orderId);
|
|
|
- $.cookie('isPayBack', 1);
|
|
|
- if (method === 'zfb') {
|
|
|
- $('body').append(
|
|
|
- $(`<div>${res.data.payInfo}</div>`)
|
|
|
- )
|
|
|
- } else if (method === 'wx') {
|
|
|
- $.cookie('isWx', 1);
|
|
|
- window.location.href = res.data.payInfo
|
|
|
+ success: function (res) {
|
|
|
+ console.log('创建订单', res)
|
|
|
+ const resData = res.data;
|
|
|
+ if (payType === 'ALIPAY') {
|
|
|
+ document.body.innerHTML = resData;
|
|
|
+ console.log(resData);
|
|
|
+
|
|
|
+ document.forms[0].submit();
|
|
|
+ } else if (payType === 'WXPAY') {
|
|
|
+
|
|
|
+ if (typeof WeixinJSBridge == "undefined") {
|
|
|
+ if (document.addEventListener) {
|
|
|
+ document.addEventListener('WeixinJSBridgeReady', onBridgeReady.bind(this, {
|
|
|
+ "appId": resData.appId,
|
|
|
+ "timeStamp": resData.timeStamp,
|
|
|
+ "nonceStr": resData.nonceStr,
|
|
|
+ "package": resData.package,
|
|
|
+ "signType": "MD5",
|
|
|
+ "paySign": resData.sign
|
|
|
+ }), false);
|
|
|
+ } else if (document.attachEvent) {
|
|
|
+ document.attachEvent('WeixinJSBridgeReady', onBridgeReady.bind(this, {
|
|
|
+ "appId": resData.appId,
|
|
|
+ "timeStamp": resData.timeStamp,
|
|
|
+ "nonceStr": resData.nonceStr,
|
|
|
+ "package": resData.package,
|
|
|
+ "signType": "MD5",
|
|
|
+ "paySign": resData.sign
|
|
|
+ }));
|
|
|
+ document.attachEvent('onWeixinJSBridgeReady', onBridgeRead.bind(this, {
|
|
|
+ "appId": resData.appId,
|
|
|
+ "timeStamp": resData.timeStamp,
|
|
|
+ "nonceStr": resData.nonceStr,
|
|
|
+ "package": resData.package,
|
|
|
+ "signType": "MD5",
|
|
|
+ "paySign": resData.sign
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ onBridgeReady({
|
|
|
+ "appId": resData.appId,
|
|
|
+ "timeStamp": resData.timeStamp,
|
|
|
+ "nonceStr": resData.nonceStr,
|
|
|
+ "package": resData.package,
|
|
|
+ "signType": "MD5",
|
|
|
+ "paySign": resData.sign
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
+ },
|
|
|
+ fail: function (res) {
|
|
|
+ showDialog('bad', '支付失败', '')
|
|
|
}
|
|
|
});
|
|
|
-}
|
|
|
+};
|
|
|
|
|
|
-const chooseProduct = (e) => {
|
|
|
- e.stopPropagation();
|
|
|
- $('.item').removeClass('focus');
|
|
|
- $(e.currentTarget).addClass('focus');
|
|
|
- productId = e.currentTarget.dataset.id.toString();
|
|
|
- $('.pay-price').html(`¥${e.currentTarget.dataset.price}元`)
|
|
|
|
|
|
+const buyTouchHandler = () => {
|
|
|
+ let mobileNumber = document.getElementById('mobile_number').value;
|
|
|
+ let signNumber = document.getElementById('sign_number').value;
|
|
|
+ if (!regTest(mobileNumber)) {
|
|
|
+ alert('手机号不规则');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const signTest = /[0-9]{4}$/;
|
|
|
+ if (!signTest.test(signNumber)) {
|
|
|
+ alert('验证码格式不正确');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let payType = aliPay ? 'ALIPAY' : 'WXPAY'
|
|
|
+ postBuyInfo(mobileNumber, signNumber, payType);
|
|
|
}
|
|
|
|
|
|
-const getSign = () => {
|
|
|
- console.log(123)
|
|
|
-}
|
|
|
|
|
|
$(document).ready(() => {
|
|
|
- if (Utils.GetQueryString('payBack') === '1') {
|
|
|
- getStatus($.cookie('orderId'))
|
|
|
+ const ua = navigator.userAgent.toLowerCase();
|
|
|
+ aliPay = ua.indexOf('alipayclient') !== -1;
|
|
|
+ wxPay = ua.indexOf('micromessenger') !== -1;
|
|
|
+ if (wxPay && !aliPay) {
|
|
|
+ if (!Utils.GetQueryString('code')) {
|
|
|
+ const url = encodeURIComponent(window.location.href)
|
|
|
+ window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf05800eea975a68b&redirect_uri=${url}&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect`
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
|
|
|
$('#sign_btn').on('click', () => {
|
|
|
getSign();
|
|
|
});
|
|
|
- $('.zfb-pay').on('click', () => {
|
|
|
- changePayWay('zfb');
|
|
|
- });
|
|
|
- $('.pay-btn').on('click', () => {
|
|
|
- if (payWay && productId) {
|
|
|
- createOrder(payWay, productId)
|
|
|
- }
|
|
|
- });
|
|
|
- $('.yes').on('click', () => {
|
|
|
- getStatus($.cookie('orderId'))
|
|
|
+
|
|
|
+ $('#buy_btn').on('click', () => {
|
|
|
+ buyTouchHandler();
|
|
|
});
|
|
|
- $('.no').on('click', () => {
|
|
|
- getStatus($.cookie('orderId'))
|
|
|
+ $('.close').on('click', () => {
|
|
|
+ $('.buy-dialog').css('display', 'none')
|
|
|
});
|
|
|
+ let price = parseInt(Utils.GetQueryString('p')) / 100;
|
|
|
+ let originPrice = parseInt(Utils.GetQueryString('op')) / 100;
|
|
|
+ if (price) {
|
|
|
+ $('#op').html(`¥${originPrice.toFixed(2)}`);
|
|
|
+ $('#minus').html(`¥${(originPrice - price).toFixed(2)}`);
|
|
|
+ $('#price').html(`¥${price.toFixed(2)}`);
|
|
|
+ console.log(decodeURIComponent(Utils.GetQueryString('name')))
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
});
|