Commit 0c6e17bc by Sweet Zhang

增加微信分享

parent 0d896972
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
<div class='closeModal' bindtap='closeModalBox'>X</div> <div class='closeModal' bindtap='closeModalBox'>X</div>
</div> </div>
<div id="d" hidden></div> <div id="d" hidden></div>
<script src="https://res2.wx.qq.com/open/js/jweixin-1.4.0.js "></script>
<script src="./js/jquery.min.js"></script> <script src="./js/jquery.min.js"></script>
<script src="js/layer.js"></script> <script src="js/layer.js"></script>
<script src="./js/base.js"></script> <script src="./js/base.js"></script>
......
...@@ -5,13 +5,13 @@ $(function () { ...@@ -5,13 +5,13 @@ $(function () {
const param = { const param = {
phone: '', phone: '',
deviceType: '', deviceType: '',
verificationCodeValider:false, verificationCodeValider: false,
customerId:'', customerId: '',
name:'', name: '',
} }
const REG_CODE = /^(1)\d{10}$/; const REG_CODE = /^(1)\d{10}$/;
const REG_NAME = /(^[\u4e00-\u9fa5]{1}[\u4e00-\u9fa5\.·。]{0,48}[\u4e00-\u9fa5]{1}$)|(^[a-zA-Z]{1}[a-zA-Z\s]{0,48}[a-zA-Z]{1}$)/; const REG_NAME = /(^[\u4e00-\u9fa5]{1}[\u4e00-\u9fa5\.·。]{0,48}[\u4e00-\u9fa5]{1}$)|(^[a-zA-Z]{1}[a-zA-Z\s]{0,48}[a-zA-Z]{1}$)/;
$("#phone,#name,#code").blur(function(){ $("#phone,#name,#code").blur(function () {
window.scrollTo(0, 0); window.scrollTo(0, 0);
}) })
var deviceType = checkDeviceType(); var deviceType = checkDeviceType();
...@@ -29,21 +29,22 @@ $(function () { ...@@ -29,21 +29,22 @@ $(function () {
}) })
return token; return token;
} }
var token = getToken(); var token = getToken();
$(".order").click(function(){ $(".order").click(function () {
$("#phone").val('') $("#phone").val('')
$("#code").val('') $("#code").val('')
$("#name").val('') $("#name").val('')
$('.modalBox').show(); $('.modalBox').show();
}) })
$('.closeModal').click(function(){ $('.closeModal').click(function () {
$('.modalBox').hide(); $('.modalBox').hide();
}) })
if(getQueryString('hmsr') || getQueryString('hmpl') || getQueryString('hmkw') || getQueryString('hmci')){ if (getQueryString('hmsr') || getQueryString('hmpl') || getQueryString('hmkw') || getQueryString('hmci')) {
window.localStorage.setItem('hmsr',getQueryString('hmsr')) window.localStorage.setItem('hmsr', getQueryString('hmsr'))
window.localStorage.setItem('hmpl',getQueryString('hmpl')) window.localStorage.setItem('hmpl', getQueryString('hmpl'))
window.localStorage.setItem('hmkw',getQueryString('hmkw')) window.localStorage.setItem('hmkw', getQueryString('hmkw'))
window.localStorage.setItem('hmci',getQueryString('hmci')) window.localStorage.setItem('hmci', getQueryString('hmci'))
} }
function getQueryString(name) { function getQueryString(name) {
const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)'); const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
...@@ -53,6 +54,7 @@ $(function () { ...@@ -53,6 +54,7 @@ $(function () {
} }
return null; return null;
} }
function checkDeviceType() { function checkDeviceType() {
if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) { if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
if (navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1) { if (navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1) {
...@@ -65,25 +67,26 @@ $(function () { ...@@ -65,25 +67,26 @@ $(function () {
} }
return deviceType; return deviceType;
} }
var deviceType = checkDeviceType(); var deviceType = checkDeviceType();
param.deviceType = deviceType; param.deviceType = deviceType;
sendPhone() sendPhone()
//发送验证码 //发送验证码
function sendPhone(){ function sendPhone() {
$("#codeBtn").click(function(){ $("#codeBtn").click(function () {
if(!$("#phone").val()){ if (!$("#phone").val()) {
layer.open({ layer.open({
content: '手机号不能为空!' content: '手机号不能为空!'
,skin: 'msg' , skin: 'msg'
,time: 3 , time: 3
}); });
return; return;
} }
if(!REG_CODE.test($("#phone").val())){ if (!REG_CODE.test($("#phone").val())) {
layer.open({ layer.open({
content: '请输入正确的手机号码!' content: '请输入正确的手机号码!'
,skin: 'msg' , skin: 'msg'
,time: 3 //2秒后自动关闭 , time: 3 //2秒后自动关闭
}); });
return; return;
} }
...@@ -91,7 +94,7 @@ $(function () { ...@@ -91,7 +94,7 @@ $(function () {
type: "POST", type: "POST",
url: api + '/api/verificationCode', url: api + '/api/verificationCode',
contentType: "application/json", contentType: "application/json",
data: JSON.stringify({type: 1,mobileNo:$("#phone").val()}), data: JSON.stringify({type: 1, mobileNo: $("#phone").val()}),
headers: {"X-Authorization": token}, headers: {"X-Authorization": token},
async: false, async: false,
success: function (res) { success: function (res) {
...@@ -101,10 +104,10 @@ $(function () { ...@@ -101,10 +104,10 @@ $(function () {
skin: 'msg', skin: 'msg',
time: 3 //2秒后自动关闭 time: 3 //2秒后自动关闭
}); });
$('#codeBtn').attr('disabled',true) $('#codeBtn').attr('disabled', true)
var timeCount = 60; var timeCount = 60;
var codeBtnHtml = '获取验证码'; var codeBtnHtml = '获取验证码';
var timer = setInterval(function() { var timer = setInterval(function () {
timeCount--; timeCount--;
codeBtnHtml = '(' + timeCount + ')s'; codeBtnHtml = '(' + timeCount + ')s';
if (timeCount <= 0) { if (timeCount <= 0) {
...@@ -126,21 +129,22 @@ $(function () { ...@@ -126,21 +129,22 @@ $(function () {
}) })
}) })
} }
checkVerificationCode ()
checkVerificationCode()
//验证验证码 //验证验证码
function checkVerificationCode () { function checkVerificationCode() {
$("#code").keyup(function(){ $("#code").keyup(function () {
if($("#code").val().length==4){ if ($("#code").val().length == 4) {
const verificationCodeRequest = { const verificationCodeRequest = {
mobileNo: $("#phone").val(), mobileNo: $("#phone").val(),
verificationCode: $("#code").val(), verificationCode: $("#code").val(),
} }
if ($("#phone").val() && $("#code").val()){ if ($("#phone").val() && $("#code").val()) {
if(!REG_CODE.test($("#phone").val())){ if (!REG_CODE.test($("#phone").val())) {
layer.open({ layer.open({
content: '请输入正确的手机号码!' content: '请输入正确的手机号码!'
,skin: 'msg' , skin: 'msg'
,time: 3 //2秒后自动关闭 , time: 3 //2秒后自动关闭
}); });
return; return;
} }
...@@ -150,8 +154,8 @@ $(function () { ...@@ -150,8 +154,8 @@ $(function () {
contentType: "application/json", contentType: "application/json",
data: JSON.stringify(verificationCodeRequest), data: JSON.stringify(verificationCodeRequest),
headers: {"X-Authorization": token}, headers: {"X-Authorization": token},
success: function(res) { success: function (res) {
param.verificationCodeValider= res.success; param.verificationCodeValider = res.success;
if (!res.success) { if (!res.success) {
layer.open({ layer.open({
content: res.message, content: res.message,
...@@ -164,9 +168,9 @@ $(function () { ...@@ -164,9 +168,9 @@ $(function () {
method: 'POST', method: 'POST',
contentType: "application/json", contentType: "application/json",
headers: {"X-Authorization": token}, headers: {"X-Authorization": token},
data: JSON.stringify({mobileNo:$("#phone").val()}), data: JSON.stringify({mobileNo: $("#phone").val()}),
success: function(res) { success: function (res) {
param.customerId= res.data.customerId; param.customerId = res.data.customerId;
if (!res.success) { if (!res.success) {
layer.open({ layer.open({
content: res.message, content: res.message,
...@@ -178,47 +182,48 @@ $(function () { ...@@ -178,47 +182,48 @@ $(function () {
}) })
} }
}) })
}else{ } else {
param.verificationCodeValider = false; param.verificationCodeValider = false;
} }
} }
}) })
} }
getPay(); getPay();
function getPay(){ function getPay() {
$("#pay").click(function(){ $("#pay").click(function () {
if (!REG_CODE.test($("#phone").val())){ if (!REG_CODE.test($("#phone").val())) {
layer.open({ layer.open({
content: '请输入正确的手机号码!' content: '请输入正确的手机号码!'
,skin: 'msg' , skin: 'msg'
,time: 3 //2秒后自动关闭 , time: 3 //2秒后自动关闭
}); });
return ; return;
}else{ } else {
param.phone = $("#phone").val() param.phone = $("#phone").val()
} }
if (!param.verificationCodeValider) { if (!param.verificationCodeValider) {
layer.open({ layer.open({
content: '请检查您的验证码是否正确' content: '请检查您的验证码是否正确'
,skin: 'msg' , skin: 'msg'
,time: 3 //2秒后自动关闭 , time: 3 //2秒后自动关闭
}); });
return ; return;
} }
if (!REG_NAME.test($("#name").val())) { if (!REG_NAME.test($("#name").val())) {
layer.open({ layer.open({
content: '请检查您的姓名是否正确!' content: '请检查您的姓名是否正确!'
,skin: 'msg' , skin: 'msg'
,time: 3 //2秒后自动关闭 , time: 3 //2秒后自动关闭
}); });
return ; return;
}else{ } else {
param.name = $("#name").val() param.name = $("#name").val()
} }
const startDate = new Date(); const startDate = new Date();
const endDate = new Date(new Date(startDate).setFullYear(new Date(startDate).getFullYear() + 1)); const endDate = new Date(new Date(startDate).setFullYear(new Date(startDate).getFullYear() + 1));
endDate.setDate(endDate.getDate()-1); endDate.setDate(endDate.getDate() - 1);
const data = { const data = {
customerId: param.customerId, customerId: param.customerId,
planId: '424', planId: '424',
...@@ -229,19 +234,19 @@ $(function () { ...@@ -229,19 +234,19 @@ $(function () {
name: param.name, name: param.name,
mobileNo: param.phone mobileNo: param.phone
}, },
channelLaunchAD:{ channelLaunchAD: {
hmsr: window.localStorage.getItem('hmsr'), hmsr: window.localStorage.getItem('hmsr'),
hmpl: window.localStorage.getItem('hmpl'), hmpl: window.localStorage.getItem('hmpl'),
hmkw: window.localStorage.getItem('hmkw'), hmkw: window.localStorage.getItem('hmkw'),
hmci: window.localStorage.getItem('hmci') hmci: window.localStorage.getItem('hmci')
}, },
deviceType:param.deviceType, deviceType: param.deviceType,
paymentMethod: '1', paymentMethod: '1',
} }
if(isWeiXin()){ if (isWeiXin()) {
data.paymentMethod='1'; data.paymentMethod = '1';
}else{ } else {
data.paymentMethod='2'; data.paymentMethod = '2';
} }
$.ajax({ $.ajax({
url: api + '/api/voucherBuy', url: api + '/api/voucherBuy',
...@@ -249,16 +254,16 @@ $(function () { ...@@ -249,16 +254,16 @@ $(function () {
contentType: "application/json", contentType: "application/json",
data: JSON.stringify(data), data: JSON.stringify(data),
headers: {"X-Authorization": token}, headers: {"X-Authorization": token},
success: function(res) { success: function (res) {
if(res['commonResult']){ if (res['commonResult']) {
if(res['content']){ if (res['content']) {
const action = res['content']['action']; const action = res['content']['action'];
const params = res['content']['param']; const params = res['content']['param'];
const actionType = res['content']['actionType']; const actionType = res['content']['actionType'];
const charset = res['content']['charset']; const charset = res['content']['charset'];
getOrPost(action, params, charset, actionType); getOrPost(action, params, charset, actionType);
} }
}else{ } else {
layer.open({ layer.open({
content: res.message, content: res.message,
skin: 'msg', skin: 'msg',
...@@ -269,13 +274,15 @@ $(function () { ...@@ -269,13 +274,15 @@ $(function () {
}) })
}) })
} }
function dateFormat(e){
if(Number(e)<10){ function dateFormat(e) {
if (Number(e) < 10) {
return '0' + e; return '0' + e;
}else{ } else {
return e; return e;
} }
} }
// 判断是get请求还是post请求进行支付请求 // 判断是get请求还是post请求进行支付请求
function getOrPost(action, params, charset, actionType) { function getOrPost(action, params, charset, actionType) {
let url = ''; let url = '';
...@@ -305,12 +312,50 @@ $(function () { ...@@ -305,12 +312,50 @@ $(function () {
document.getElementById('submit').click() document.getElementById('submit').click()
} }
} }
function isWeiXin(){
function isWeiXin() {
var ua = window.navigator.userAgent.toLowerCase(); var ua = window.navigator.userAgent.toLowerCase();
if(ua.match(/MicroMessenger/i) == 'micromessenger' || ua.match(/_SQ_/i) == '_sq_'){ if (ua.match(/MicroMessenger/i) == 'micromessenger' || ua.match(/_SQ_/i) == '_sq_') {
return true; return true;
}else{ } else {
return false; return false;
} }
} }
getWxConfig();
// 获取微信分享配置
function getWxConfig()
{
var url = location.href.split('#')[0];
$.ajax({
type: "POST",
url: api + '/api/wxConfig',
contentType: "application/json",
data: JSON.stringify({url: url}),
headers: {"X-Authorization": token},
async: false,
success: function (res) {
wx.config({
debug: false,
appId: res.data.appId,
timestamp: res.data.timestamp,
nonceStr: res.data.nonceStr,
signature: res.data.signature,
jsApiList: res.data.jsApiList,
beta: true
});
// 默认的分享信息
const shareData = {
title: '1对1家庭风险管理服务',
link: window.location.href,
desc: '产品太多、条款复杂、买哪个好,理不理赔? 獴哥保险工作室来帮您解决,提供1对1风险分析和保险方案定制。',
imgUrl: 'https://ajb-images.oss-cn-shanghai-finance-1-pub.aliyuncs.com/images/menggo_head.png'
};
wx.ready(function () {
wx.onMenuShareAppMessage(shareData); // 分享微信
wx.onMenuShareTimeline(shareData); // 分享到朋友圈
wx.onMenuShareQQ(shareData); // 分享到QQ
});
}
})
}
}); });
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment