Commit 71ff1677 authored by jiaoyahui's avatar jiaoyahui

授权下微信支付

parent 0920ef4f
......@@ -58,9 +58,13 @@ live: {
},
buy:function(data){
return service.post('/oapi/v1/h5/pay/buy', data)
},
buy_code:function(data){
return service.post('/wx/code', data)
}
},
}
......
......@@ -184,7 +184,7 @@ router.beforeEach((to, from, next) => {
} else {
console.log('该页面需要登陆')
next({
path: '/login',
// path: '/login',进页面直接进去登录页面先隐藏
// query: { redirect: to.fullPath } // 将跳转的路由path作为参数,登录成功后跳转到该路由
})
}
......
......@@ -96,12 +96,12 @@
<div class="div_p">{{item.chargeModeName}}</div>
<div class="Uimg">
<img src="../assets/niu.png" alt="" class="sent_r">
<span>20</span>
<span>{{item.lvrfFee}} </span>
</div>
<div class="Mar_p">
<img src="../assets/niu.png" alt="" class="U_both">
<span class="d_num">200/节</span>
<span class="d_num">{{item.promptFee}}/月</span>
</div>
</div>
......@@ -191,6 +191,7 @@
</div>
<div class="gr"><img src="../assets/login.png" alt="" class="Pl" @click="login_t"></div>
<img :src="'data:image/png;base64,'+ qrcodeSrc" alt="" >
</div>
......@@ -216,6 +217,7 @@ export default {
data() {
return {
n : 1,
qrcodeSrc:'',
chargeModeKey:'Month',
is_xuanzhong : 'Month0',
is_Month : 'Month',
......@@ -269,9 +271,14 @@ export default {
pmoId:'',
pmoOrder:'',
active_p:'Month',
currentIndex:0
// is_show_p:false //默认选中按钮隐藏
currentIndex:0,
isMobile: false,
wechatInfo:'',
//is_show_p:false //默认选中按钮隐藏
// orderType : 4, //pc浏览器环境
// orderType : 3, //h5环境
wxOrderType: this.common.isMobile() && this.common.isWX() ? 2 : (this.common.isMobile() ? 3 : 4),
};
},
......@@ -280,6 +287,8 @@ export default {
this.videoList()
this.getHeight()
this.pay_info()
this.isMobile = this.common.isMobile();
// 连接mqtt
mqtt.connect({
user: request.mqtt.mqttUser,
......@@ -471,17 +480,11 @@ export default {
pay_info(){
let temp=this.qs.stringify({
pmAppVersion:'884',
// pmModel:'iPhone 12/13 (Pro)',
// pmSystem:'iOS 10.0.1',
// timestamp:this.timestamp,
// goodsId:115,
// pmOperator:'无运营商',
applicationType:4,
pmAppVersion: 868,
// applicationType: 3,
goodsType:3,
goodsId:429,
goodsId:285,
})
this.server.live.payinfo(temp).then(res=>{
this.udRealname=res.data.data.udRealname
......@@ -497,7 +500,7 @@ export default {
// 订单
payorder(){
let temp=this.qs.stringify({
goodsId:429,
goodsId:285,
goodsType:3,
sxUbId:26,
pmoType:0,
......@@ -510,45 +513,71 @@ export default {
isCheckBuy:1,
paySource:"douniu_h5",
chargeModeKey:this.chargeModeKey
})
this.server.live.order(temp).then(res=>{
this.pmoId=res.data.data.pmoId,
this.pmoOrder=res.data.data.pmoOrder
//order成功判断内置浏览器,在微信就授权,内置微信还是浏览器 微信jsapi 浏览器h5
if(res.code=200){
//判断是否为在微信内置浏览器支付
if(this.common.isWX()){
// this.a_go()
// this.pay_code() //授权登录
}else{
console.log(res.data.data.pmoOrder,'===-')
}
this.paybuy()
}
})
},
paybuy(){
//判断在微信内置浏览器jsapi支付
//jsapi
let temp=this.qs.stringify({
orderId:this.pmoId,
orderNo:this.pmoOrder,
payType:1,
orderType:3,
orderType: this.wxOrderType,
pmoType:0,
goodsType:3,
})
this.server.live.buy(temp).then(res=>{
window.location.href=res.data.data.wechatInfo.payUrl
console.log(res.data.data.wechatInfo.payUrl,'===')
// this.qrcodeSrc=res.data.data.wechatInfo.base64Img;
// alert(11)
// this.codeUrl=res.data.data.wechatInfo.codeUrl
//h5 window.location.href=res.data.data.wechatInfo.payUrl
// window.location.href=res.data.data.wechatInfo.codeUrl
// console.log(res.data.data.wechatInfo.payUrl,'===')
this.qrcodeSrc=res.data.data.wechatInfo.base64Img;
this.wechatInfo=res.data.data.wechatInfo
//微信内置jsapi
if(this.wxOrderType == 2){
this.onBridgeReady();
}
//二维码
if(this.wxOrderType == 4){
//弹窗展示二维码
this.qrcodeSrc=res.data.data.wechatInfo.base64Img;
}
//移动端外部浏览器
if(this.wxOrderType == 3){
//跳转h5支付链接
window.location.href=res.data.data.wechatInfo.payUrl
}
})
},
videoClick(lv){
this.playerOptions.sources[0].src=lv
......@@ -574,7 +603,7 @@ export default {
},
login_t(){
this.payorder()
// this.pay_code()
if(!this.isImg_show){
this.a_plert=true
return;
......@@ -595,7 +624,57 @@ export default {
this.pten = true
},
onBridgeReady() {
WeixinJSBridge.invoke('getBrandWCPayRequest', {
"appId": this.wechatInfo.appId, //公众号ID,由商户传入
"timeStamp": this.wechatInfo.timeStamp, //时间戳,自1970年以来的秒数
"nonceStr":this.wechatInfo.nonceStr, //随机串
// "package": `prepay_id=${this.wechatInfo.prepayId}`,
"package": this.wechatInfo.packAge,
"signType":this.wechatInfo.signType, //微信签名方式:
"paySign":this.wechatInfo.sign
// "paySign": "oR9d8PuhnIc+YZ8cBHFCwfgpaK9gd7vaRvkYD7rthRAZ\/X+QBhcCYL21N7cHCTUxbQ+EAt6Uy+lwSN22f5YZvI45MLko8Pfso0jm46v5hqcVwrk6uddkGuT+Cdvu4WBqDzaDjnNa5UK3GfE1Wfl2gHxIIY5lLdUgWFts17D4WuolLLkiFZV+JSHMvH7eaLdT9N5GBovBwu5yYKUR7skR8Fu+LozcSqQixnlEZUfyE55feLOQTUYzLmR9pNtPbPsu6WVhbNHMS3Ss2+AehHvz+n64GDmXxbX++IOBvm2olHu3PsOUGRwhudhVf7UcGcunXt8cqNjKNqZLhLw4jq\/xDg==" //微信签名
},
function(res) {
if (res.err_msg == "get_brand_wcpay_request:ok") {
// 使用以上方式判断前端返回,微信团队郑重提示:
//res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
}
});
}
// if (typeof WeixinJSBridge == "undefined") {
// if (document.addEventListener) {
// document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
// } else if (document.attachEvent) {
// document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
// document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
// }
// } else {
// onBridgeReady();
// }
// a_go(){
// if (this.common.isWX() && this.common.isMobile()) { //微信浏览器
// // 转换为query格式
// var urlParam = this.$route.query.path;
// if(!this.$route.query.path){
// urlParam='undefined'
// }
// var urlTag = this.qs.stringify({
// urlTag: this.getPath(),
// urlParam: urlParam,
// });
// this.server.base.buy_code(urlTag).then(res => {
// location.href = res.data.data;
// })
// } else {
// // this.getLive()
// this.$router.push({
// path:'/live',
// });
// }
// }
},
};
......@@ -923,7 +1002,7 @@ display: block;
}
.conten{
position:fixed;
top:24%;
top:0%;
left:0%;
width:100%;
/* background:red */
......
......@@ -297,6 +297,7 @@ export default {
window.sessionStorage.setItem('token', thisToken);
sessionStorage.setItem("name", name);
store.commit("SET_TOKEN", thisToken);
// this.getLive()
this.$router.push(
{
......
// 判断是否为微信浏览器
const isWX = () => {
var ua = navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == 'micromessenger') {
// 秒数转时间格式
function secondToTime(item) {
if (typeof item != 'number' || isNaN(item)) {
return '00:00';
}
var s = item % 60 < 10 ? '0' + item % 60 : (item % 60).toString();
item = parseInt(item / 60);
if (item == 0) {
return '00:' + s;
}
var m = item < 10 ? '0' + item : item.toString();
return m + ":" + s;
}
// 手机号校验
const checkPhone = (value) => {
var reg = /^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8,9])|(18[0-9])|(19[8|9]))\d{8}$/
if (reg.test(value)) {
return true;
} else {
return false;
}
};
// 判断数字
const checkNumber = (item) => {
if (!item) {
return ''
}
var reg = /^[0-9]$/
if (reg.test(item.charAt(item.length - 1))) {
return item;
} else {
return item.slice(0, item.length - 1)
}
// 判断是否为移动端浏览器
};
// 判断是否为移动端浏览器
const isMobile = () => {
var ua = navigator.userAgent;
var ipad = ua.match(/(iPad).*OS\s([\d_]+)/),
......@@ -20,4 +50,73 @@ const isMobile = () => {
} else {
return false;
}
}
// 判断是否为微信浏览器
const isWX = () => {
var ua = navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == 'micromessenger') {
return true;
} else {
return false;
}
}
// 随机字符串
function randomString(length) {
var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
var result = '';
for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
return result;
}
// 设置微信分享
function setWXShare(item) {
if (isWX() && wx) {
var link = window.location.href.split('#/')[0] + '#/';
var acceptPath = ['/NiuCeLue', '/NiuRenKe', '/NiuRenKe/video', '/singleVideo', '/NiuRenKe/audio',
'/singleAudio', '/liveDetail', '/repeatDetail'
];
var schema = 'http://';
if (link.indexOf('https') != -1) {
schema = 'https://';
}
for (var i in acceptPath) {
if (window.location.href.split('#')[1].split('?')[0] == acceptPath[i]) {
link = schema + window.location.host + '/#' + window.location.href.split('#')[1];
}
}
link = link.replace('?from=singlemessage', '');
wx.ready(() => { //需在用户可能点击分享按钮前就先调用
wx.updateAppMessageShareData({
title: '斗牛财经', // 分享标题
desc: item.title, // 分享描述
link: link, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: item.imgUrl, // 分享图标
success: function () {
console.log("分享成功")
}
})
});
}
}
// 签名
function sign(timestamp, type, phone) {
var str = "timestamp=" + timestamp + "&type=" + type + "&ubPhone=" + phone + "&key=" + store.state.signKey;
return str;
}
export default {
secondToTime,
checkPhone,
checkNumber,
isMobile,
isWX,
randomString,
setWXShare,
sign,
}
\ 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