You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
190 lines
4.9 KiB
190 lines
4.9 KiB
var jweixin = require('jweixin-module');
|
|
console.log(jweixin,'jweixin是啥')
|
|
|
|
export default {
|
|
//判断是否在微信中
|
|
//安平公众号密钥:458337c7120a41c1327cc1ee0d1272ae
|
|
//石家庄公众号密钥:670ee544621ddfb46b41a38f53648526
|
|
isWechat: function() {
|
|
var ua = window.navigator.userAgent.toLowerCase();
|
|
if (ua.match(/micromessenger/i) == 'micromessenger') {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
},
|
|
initJssdk: function(callback) {
|
|
var url = 'http://144.7.116.46:10001/mobile/wechat/getWeiXinSDKSign.do';
|
|
var data = {
|
|
url: "http://144.7.116.46:10001/h5/index.html"
|
|
};
|
|
|
|
uni.request({
|
|
url: url, //仅为示例,并非真实接口地址。
|
|
data: data,
|
|
success: (res) => {
|
|
console.log("--------------------------");
|
|
console.log(res);
|
|
console.log(res.data.data.appId);
|
|
jweixin.config({
|
|
debug: false,
|
|
appId: res.data.data.appId,
|
|
timestamp: res.data.data.timestamp,
|
|
nonceStr: res.data.data.nonceStr,
|
|
signature: res.data.data.signature,
|
|
jsApiList: [
|
|
'checkJsApi',
|
|
'getLocation',
|
|
'openLocation',
|
|
'startRecord',
|
|
'stopRecord',
|
|
'onVoiceRecordEnd',
|
|
'translateVoice',
|
|
'chooseWXPay'
|
|
]
|
|
});
|
|
|
|
if (callback) {
|
|
callback(res.data);
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
},
|
|
getLocation: function(successCallbck, failCallback) {
|
|
this.initJssdk(
|
|
function(res) {
|
|
jweixin.ready(function() {
|
|
console.log("----获取定位---");
|
|
|
|
jweixin.getLocation({
|
|
type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
|
|
success: function(res) {
|
|
console.log(res);
|
|
if (successCallbck) {
|
|
successCallbck(res);
|
|
}
|
|
},
|
|
fail: function(res) {
|
|
if (failCallback) {
|
|
failCallback(res);
|
|
}
|
|
}
|
|
});
|
|
})
|
|
}
|
|
);
|
|
},
|
|
pay: function(obj,successCallbck) {
|
|
this.initJssdk(
|
|
function(res_data) {
|
|
jweixin.ready(function() {
|
|
console.log("----进行支付---");
|
|
jweixin.chooseWXPay({
|
|
timestamp: obj.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
|
|
nonceStr: obj.nonceStr, // 支付签名随机串,不长于 32 位
|
|
package: obj.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
|
|
signType: obj.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
|
|
paySign: obj.paySign, // 支付签名
|
|
success: function (res) {
|
|
uni.showModal({content:JSON.stringify(res)})
|
|
// 支付成功后的回调函数
|
|
if(res.errMsg == "chooseWXPay:ok" ){
|
|
// 使用以上方式判断前端返回,微信团队郑重提示:
|
|
//res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
|
|
successCallbck();
|
|
}else if(res.errMsg == "chooseWXPay:fail" ){
|
|
uni.showToast({
|
|
icon:"none",
|
|
title:res.errMsg
|
|
})
|
|
}else{
|
|
uni.showToast({
|
|
icon:"none",
|
|
title:"支付取消"
|
|
})
|
|
}
|
|
}
|
|
});
|
|
})
|
|
}
|
|
);
|
|
},
|
|
openLocation: function(mapParam) {
|
|
this.initJssdk(function(res) {
|
|
|
|
jweixin.ready(function() {
|
|
console.log("------打开地图----");
|
|
jweixin.openLocation({
|
|
latitude: Number(mapParam.latitude),
|
|
longitude: Number(mapParam.longitude),
|
|
scale: mapParam.scale,
|
|
name: mapParam.name,
|
|
address: mapParam.address,
|
|
success: function() {
|
|
console.log('success');
|
|
}
|
|
|
|
})
|
|
});
|
|
});
|
|
},
|
|
//开始录音
|
|
startRecord: function(successCallbck, failCallback) {
|
|
this.initJssdk(
|
|
function(res) {
|
|
jweixin.ready(function() {
|
|
jweixin.startRecord({
|
|
success: function(res) {
|
|
console.log(res);
|
|
if (successCallbck) {
|
|
successCallbck(res);
|
|
}
|
|
},
|
|
fail: function(res) {
|
|
if (failCallback) {
|
|
failCallback(res);
|
|
}
|
|
}
|
|
});
|
|
})
|
|
}
|
|
);
|
|
},
|
|
//结束录音
|
|
stopRecord: function(successCallbck, failCallback) {
|
|
this.initJssdk(
|
|
function(res) {
|
|
jweixin.ready(function() {
|
|
jweixin.stopRecord({
|
|
success: function(res) {
|
|
var localId = res.localId;
|
|
//识别录音转文字
|
|
jweixin.translateVoice({
|
|
localId: localId, // 需要识别的音频的本地Id,由录音相关接口获得
|
|
isShowProgressTips: 1, // 默认为1,显示进度提示
|
|
success: function (res) {
|
|
if (successCallbck) {
|
|
successCallbck(res);
|
|
}
|
|
},
|
|
fail: function(res) {
|
|
if (failCallback) {
|
|
failCallback(res);
|
|
}
|
|
}
|
|
});
|
|
|
|
},
|
|
fail: function(res) {
|
|
if (failCallback) {
|
|
failCallback(res);
|
|
}
|
|
}
|
|
});
|
|
})
|
|
}
|
|
);
|
|
},
|
|
}
|
|
|