初始化(包含登录模块)
This commit is contained in:
63
config/baseUrl.js
Normal file
63
config/baseUrl.js
Normal file
@@ -0,0 +1,63 @@
|
||||
let baseUrl = "";
|
||||
let socketUrl = "";
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
// 开发环境
|
||||
// baseUrl = "http://localhost:7001/";
|
||||
// socketUrl = "ws://localhost:6001/";
|
||||
// baseUrl = "https://twin-ui.com/demo/";
|
||||
// baseUrl = "https://testapi.nuttyreading.com/"; // 线上测试环境
|
||||
baseUrl = "https://api.nuttyreading.com/"; // 线上正式
|
||||
// baseUrl = "http://192.168.110.100:9200/pb/"; // 开发用电脑
|
||||
// baseUrl = "http://59.110.212.44:9200/pb/";
|
||||
// baseUrl = "http://192.168.110.100:9100/pb/"; // 开发用电脑
|
||||
// baseUrl = "http://192.168.110.110:9200/pb/";
|
||||
// baseUrl = "http://192.168.110.38:9200/pb/"; // 吴春磊笔记本1
|
||||
// socketUrl = "ws://8.129.186.35:6001/";
|
||||
} else if (process.env.NODE_ENV === 'production') {
|
||||
// 生产环境11
|
||||
// baseUrl = "http://59.110.212.44:9100/pb/";
|
||||
// baseUrl = "https://testapi.nuttyreading.com/";
|
||||
baseUrl = "https://api.nuttyreading.com/"; //1
|
||||
// baseUrl = "ws://twin-ui.com:6001/";
|
||||
// socketUrl = "ws://twin-ui.com:6001/";
|
||||
}
|
||||
const courtConfig = {
|
||||
//微信公众号APPID
|
||||
publicAppId: "",
|
||||
//请求接口
|
||||
baseUrl: baseUrl,
|
||||
//webSocket地址
|
||||
socketUrl: socketUrl,
|
||||
//平台名称
|
||||
platformName: "uniApp-案例",
|
||||
//项目logo
|
||||
logoUrl: "https://qn.kemean.cn/upload/201906/19/3f3b4751f3ed4a97be804450c3ec4c79",
|
||||
//页面分享配置
|
||||
share: {
|
||||
title: 'uniApp-案例',
|
||||
// #ifdef MP-WEIXIN
|
||||
path: '/pages/home/home', //小程序分享路径
|
||||
// #endif
|
||||
// #ifdef H5 || APP-PLUS
|
||||
//公众号||APP分享
|
||||
desc: "uniApp-案例", // 分享描述
|
||||
link: "https://www.kemean.com/sameCity/18031201/index.html", // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
|
||||
imgUrl: "http://qn.kemean.cn/upload/201901/28/23bedfc34597482292ecd6dc107f6342", // 分享图标
|
||||
// #endif
|
||||
}
|
||||
};
|
||||
//手机号验证正则表达式
|
||||
// (中国大陆)
|
||||
const phoneRegular = /^1\d{10}$/;
|
||||
// 手机号码验证 支持港澳台 大陆
|
||||
// const phoneRegular = /^[1][3-8]\d{9}$|^([6|9])\d{7}$|^[0][9]\d{8}$|^[6]([8|6])\d{5}$|^(00){0,1}(65){1}[13689]\d{6,7}$/;
|
||||
//邮箱验证正则表达式
|
||||
const mailRegular = /^\w+([-+._']\w+)*@\w+(\.[a-zA-Z]{2,3}){1,2}$/;
|
||||
//密码验证正则表达式
|
||||
// const passwordRegular = /^[a-zA-Z0-9]{4,10}$/;
|
||||
const passwordRegular = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/;
|
||||
export default Object.assign({
|
||||
phoneRegular,
|
||||
mailRegular,
|
||||
passwordRegular
|
||||
}, courtConfig);
|
||||
76
config/componentConfig.js
Normal file
76
config/componentConfig.js
Normal file
@@ -0,0 +1,76 @@
|
||||
import $http from '@/config/requestConfig'
|
||||
const platform = uni.getSystemInfoSync().platform;
|
||||
export default {
|
||||
/****************以下是z-nav-bar插件配置*******************/
|
||||
// 主页页面的页面路径
|
||||
// 关联功能:打开的页面只有一个的时候右上角自动显示返回首页按钮,下面这个数组是排除显示返回首页的页面。
|
||||
// 主页使用场景:小程序分享出去的页面,用户点击开是分享页面,很多情况下是没有返回首页按钮的
|
||||
mainPagePath: ['pages/homePage/index'],
|
||||
//返回首页的地址
|
||||
homePath: '/pages/homePage/index',
|
||||
|
||||
/****************以下是zhouWei-APPUpdate插件配置*******************/
|
||||
// 发起ajax请求获取服务端版本号
|
||||
getServerNo: (version, isPrompt = false, callback) => {
|
||||
let httpData = {
|
||||
version: version.versionCode,
|
||||
// 版本名称
|
||||
versionName: version.versionName,
|
||||
// setupPage参数说明(判断用户是不是从设置页面点击的更新,如果是设置页面点击的更新,有不要用静默更新了,不然用户点击没反应很奇怪的)
|
||||
setupPage: isPrompt
|
||||
};
|
||||
if (platform == "android") {
|
||||
httpData.type = 1101;
|
||||
} else {
|
||||
httpData.type = 1102;
|
||||
}
|
||||
/* 接口入参说明
|
||||
* version: 应用当前版本号(已自动获取)
|
||||
* versionName: 应用当前版本名称(已自动获取)
|
||||
* type:平台(1101是安卓,1102是IOS)
|
||||
*/
|
||||
/****************以下是示例*******************/
|
||||
// 可以用自己项目的请求方法
|
||||
$http.get("api/common/v1/app_version", httpData,{
|
||||
isPrompt: isPrompt
|
||||
}).then(res => {
|
||||
/* res的数据说明
|
||||
* | 参数名称 | 一定返回 | 类型 | 描述
|
||||
* | -------------|--------- | --------- | ------------- |
|
||||
* | versionCode | y | int | 版本号 |
|
||||
* | versionName | y | String | 版本名称 |
|
||||
* | versionInfo | y | String | 版本信息 |
|
||||
* | updateType | y | String | forcibly = 强制更新, solicit = 弹窗确认更新, silent = 静默更新 |
|
||||
* | downloadUrl | y | String | 版本下载链接(IOS安装包更新请放跳转store应用商店链接,安卓apk和wgt文件放文件下载链接) |
|
||||
*/
|
||||
if (res && res.downloadUrl) {
|
||||
// 判断用户是不是从设置页面点击的更新,如果是设置页面点击的更新,无视接口给的更新类型,强制修改为弹窗确认更新
|
||||
if(isPrompt){
|
||||
res.updateType = "solicit";
|
||||
}
|
||||
|
||||
// 兼容之前的版本(updateType是新版才有的参数)
|
||||
if(res.updateType){
|
||||
callback && callback(res);
|
||||
} else {
|
||||
if(res.forceUpdate){
|
||||
res.updateType = "forcibly";
|
||||
} else {
|
||||
res.updateType = "solicit";
|
||||
}
|
||||
callback && callback(res);
|
||||
}
|
||||
} else if (isPrompt) {
|
||||
uni.showToast({
|
||||
title: "暂无新版本",
|
||||
icon: "none"
|
||||
});
|
||||
}
|
||||
});
|
||||
/****************以上是示例*******************/
|
||||
},
|
||||
// 弹窗主颜色(不填默认粉色)
|
||||
appUpdateColor: "f00",
|
||||
// 弹窗图标(不填显示默认图标,链接配置示例如: '/static/demo/ic_attention.png')
|
||||
appUpdateIcon: ''
|
||||
}
|
||||
268
config/html5Utils.js
Normal file
268
config/html5Utils.js
Normal file
@@ -0,0 +1,268 @@
|
||||
import base from '@/config/baseUrl';
|
||||
import store from '@/store';
|
||||
import $http from '@/config/requestConfig'
|
||||
import { getLocation, setShare } from '@/plugins/wxJsSDK';
|
||||
|
||||
/**
|
||||
* APP内嵌网页 -- 安卓IOS交互
|
||||
* 交互区分名称:shangChengView
|
||||
* 示例:appMutual("方法名称", "传递的参数")
|
||||
* 相当与安卓交互:window.shangChengView["方法名称"]("传递的参数");
|
||||
*/
|
||||
export const appMutual = (name, query = null, errCallback) => {
|
||||
if (/android/i.test(navigator.userAgent)) {
|
||||
if (window.shangChengView) {
|
||||
if (typeof(query) == "object") {
|
||||
query = JSON.stringify(query);
|
||||
}
|
||||
window.shangChengView[name](query);
|
||||
} else {
|
||||
errCallback && errCallback();
|
||||
}
|
||||
} else if (/ios|iphone|ipod|pad/i.test(navigator.userAgent)) {
|
||||
if (window.webkit) {
|
||||
window.webkit.messageHandlers[name].postMessage(query)
|
||||
} else {
|
||||
errCallback && errCallback();
|
||||
}
|
||||
}
|
||||
};
|
||||
/**
|
||||
* 获取url中的参数
|
||||
*/
|
||||
export const getUrlData = () => {
|
||||
var strs;
|
||||
var url = window.location.href; //获取url中"?"符后的字串
|
||||
var theRequest = new Object();
|
||||
if (url.indexOf("?") != -1) {
|
||||
url = url.substr(url.indexOf("?"));
|
||||
var str = url.substr(1);
|
||||
strs = str.split("&");
|
||||
for (var i = 0; i < strs.length; i++) {
|
||||
var index = strs[i].indexOf("=");
|
||||
theRequest[strs[i].slice(0, index)] = unescape(strs[i].slice(index + 1, strs[i].length));
|
||||
}
|
||||
}
|
||||
|
||||
return theRequest;
|
||||
}
|
||||
//公众号微信支付
|
||||
export const wxPublicPay = (payInfo, callback) => {
|
||||
$http.get("api/pay/v1/pay_public_wx", {
|
||||
orderNo: payInfo.orderNo
|
||||
}).then(data => {
|
||||
let wxConfigObj = {
|
||||
appId: data.appId,
|
||||
timeStamp: data.timeStamp,
|
||||
nonceStr: data.nonceStr,
|
||||
package: data.package,
|
||||
signType: data.signType,
|
||||
paySign: data.sign
|
||||
};
|
||||
function onBridgeReady() {
|
||||
window.WeixinJSBridge.invoke("getBrandWCPayRequest", wxConfigObj, function(
|
||||
res
|
||||
) {
|
||||
if (res.err_msg == "get_brand_wcpay_request:ok") {
|
||||
callback && callback(res);
|
||||
} else // 使用以上方式判断前端返回,微信团队郑重提示:res.err_msg将在用户支付成功后返回 ok,但并不保证它绝对可靠。
|
||||
if (res.err_msg == "get_brand_wcpay_request:cancel") {
|
||||
// common.loadWarn('支付遇到问题,您取消了支付');
|
||||
} else
|
||||
if (res.err_msg == "get_brand_wcpay_request:fail") {
|
||||
// common.myConfirm('支付遇到问题,您可能需要重新登录', '', function () {
|
||||
// obj.wxLoginOAuth();
|
||||
// });
|
||||
}
|
||||
});
|
||||
}
|
||||
if (typeof window.WeixinJSBridge == "undefined") {
|
||||
if (document.addEventListener) {
|
||||
document.addEventListener("WeixinJSBridgeReady", onBridgeReady, false);
|
||||
} else if (document.attachEvent) {
|
||||
document.attachEvent("WeixinJSBridgeReady", onBridgeReady);
|
||||
document.attachEvent("onWeixinJSBridgeReady", onBridgeReady);
|
||||
}
|
||||
} else {
|
||||
onBridgeReady();
|
||||
}
|
||||
});
|
||||
};
|
||||
// 浏览器判断
|
||||
export const getBrowser = () => {
|
||||
let ua = navigator.userAgent.toLowerCase();
|
||||
if (ua.match(/MicroMessenger/i) == "micromessenger") {
|
||||
return "微信";
|
||||
}
|
||||
return "其他";
|
||||
};
|
||||
// 获取地址信息(公众号获取 或 内嵌APP获取)
|
||||
export const getLatLonH5 = function(successCallback, errCallback) {
|
||||
if (getBrowser() == '微信') {
|
||||
getLocation().then(res => {
|
||||
successCallback(res);
|
||||
}, err => {
|
||||
console.log("位置信息错误", err);
|
||||
errCallback("位置信息获取失败");
|
||||
});
|
||||
} else {
|
||||
let clearTime = setTimeout(() => {
|
||||
errCallback("获取经纬度超时");
|
||||
}, 5000);
|
||||
window.getAppLatLon = function(res) {
|
||||
clearTimeout(clearTime);
|
||||
successCallback(res);
|
||||
}
|
||||
appMutual("getAppLatLon", true);
|
||||
}
|
||||
};
|
||||
// 公众号分享
|
||||
export const publicShareFun = function (info = {},callback) {
|
||||
if (getBrowser() == "微信") {
|
||||
let shareInfo = {
|
||||
title: info.shareTitle || info.title || base.share.title,
|
||||
desc: info.desc || info.shareContent || base.share.desc,
|
||||
imgUrl: info.imgUrl || info.shareImg || base.share.imgUrl,
|
||||
link: info.link || info.shareUrl || base.share.link,
|
||||
};
|
||||
if (store.state.userInfo.token) {
|
||||
if (shareInfo.link.indexOf("?") >= 0) {
|
||||
shareInfo.link += "&recommendCode=" + store.state.userInfo.uid;
|
||||
} else {
|
||||
shareInfo.link += "?recommendCode=" + store.state.userInfo.uid;
|
||||
}
|
||||
}
|
||||
setShare(shareInfo, callback);
|
||||
}
|
||||
}
|
||||
|
||||
//公众号获取code
|
||||
function getLogin(type) {
|
||||
let urlNow = encodeURIComponent(window.location.href);
|
||||
let url =
|
||||
`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${
|
||||
base.publicAppId
|
||||
}&redirect_uri=${urlNow}&response_type=code&scope=snsapi_userinfo&state=${type}#wechat_redirect`;
|
||||
window.location.replace(url);
|
||||
}
|
||||
//判断是否登录,登录处理
|
||||
let isGetOpenId = true;
|
||||
function getRecommendCode() {
|
||||
var url = window.location.href;
|
||||
let codeIndex = url.indexOf("recommendCode=");
|
||||
if (codeIndex >= 0) {
|
||||
let recommendCode = url.substr(codeIndex + 14);
|
||||
if (recommendCode.indexOf("&") >= 0) {
|
||||
return recommendCode.substr(0, recommendCode.indexOf("&"));
|
||||
} else if (recommendCode.indexOf("?") >= 0) {
|
||||
return recommendCode.substr(0, recommendCode.indexOf("?"));
|
||||
} else if (recommendCode.indexOf("/") >= 0) {
|
||||
return recommendCode.substr(0, recommendCode.indexOf("/"));
|
||||
} else if (recommendCode.indexOf("#") >= 0) {
|
||||
return recommendCode.substr(0, recommendCode.indexOf("#"));
|
||||
}
|
||||
return recommendCode;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
function getRecommend() {
|
||||
var url = window.location.href;
|
||||
let codeIndex = url.indexOf("recommend=");
|
||||
if (codeIndex >= 0) {
|
||||
let recommend = url.substr(codeIndex + 10);
|
||||
if (recommend.indexOf("&") >= 0) {
|
||||
return recommend.substr(0, recommend.indexOf("&"));
|
||||
} else if (recommend.indexOf("?") >= 0) {
|
||||
return recommend.substr(0, recommend.indexOf("?"));
|
||||
} else if (recommend.indexOf("/") >= 0) {
|
||||
return recommend.substr(0, recommend.indexOf("/"));
|
||||
} else if (recommend.indexOf("#") >= 0) {
|
||||
return recommend.substr(0, recommend.indexOf("#"));
|
||||
}
|
||||
return recommend;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
export const h5Login = function(type = "judge", callback) {
|
||||
var getRequest = getUrlData();
|
||||
let recommendCode = getRecommendCode();
|
||||
if (recommendCode && recommendCode !== "null" && recommendCode !== "undefined") {
|
||||
uni.setStorageSync("recommendCode", recommendCode);
|
||||
} else {
|
||||
let recommend = getRecommend();
|
||||
if(recommend && recommend !== "null" && recommend !== "undefined"){
|
||||
uni.setStorageSync("recommendCode", recommend);
|
||||
}
|
||||
}
|
||||
if (getBrowser() == "微信") {
|
||||
if (getRequest.code) {
|
||||
if(isGetOpenId){
|
||||
isGetOpenId = false;
|
||||
let httpData = {
|
||||
code: getRequest.code
|
||||
};
|
||||
let recommendCode = uni.getStorageSync("recommendCode");
|
||||
if(recommendCode){
|
||||
httpData.recommendUid = recommendCode;
|
||||
store.commit("setChatScenesInfo", {
|
||||
recommendCode: recommendCode
|
||||
});
|
||||
uni.removeStorageSync("recommendCode");
|
||||
}
|
||||
$http.get("api/open/v2/get_public_login", httpData)
|
||||
.then(result => {
|
||||
store.commit('setUserInfo', result);
|
||||
//publicShare();
|
||||
callback && callback();
|
||||
uni.showToast({
|
||||
title: "欢迎回来",
|
||||
icon: "none"
|
||||
});
|
||||
},() => {
|
||||
isGetOpenId = true;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
getLogin(type);
|
||||
}
|
||||
} else {
|
||||
if (getRequest.userToken) {
|
||||
store.commit('setUserInfo', {
|
||||
token: getRequest.userToken
|
||||
});
|
||||
$http.get("api/mime/v1/info").then(res => {
|
||||
store.commit('setUserInfo', res);
|
||||
callback && callback();
|
||||
});
|
||||
} else {
|
||||
appMutual("jumpLogin", null, function() {
|
||||
if (type == "force") {
|
||||
// 没登录跳转回登录页
|
||||
uni.showToast({
|
||||
icon: 'none',
|
||||
title: '用户信息失效,请重新登陆。'
|
||||
})
|
||||
uni.navigateTo({
|
||||
url: "/pages/user/login"
|
||||
});
|
||||
}else{
|
||||
uni.showModal({
|
||||
title:"提示",
|
||||
content:"您还未登录,请先登录~",
|
||||
confirmText: "去登录",
|
||||
cancelText: "再逛会",
|
||||
success: (res) => {
|
||||
if(res.confirm){
|
||||
uni.navigateTo({
|
||||
url: "/pages/user/login"
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
126
config/iap.js
Normal file
126
config/iap.js
Normal file
@@ -0,0 +1,126 @@
|
||||
// uni iap
|
||||
|
||||
const ProviderType = {
|
||||
IAP: 'iap'
|
||||
}
|
||||
|
||||
const IapTransactionState = {
|
||||
purchasing: "0", // A transaction that is being processed by the App Store.
|
||||
purchased: "1", // A successfully processed transaction.
|
||||
failed: "2", // A failed transaction.
|
||||
restored: "3", // A transaction that restores content previously purchased by the user.
|
||||
deferred: "4" // A transaction that is in the queue, but its final status is pending external action such as Ask to Buy.
|
||||
};
|
||||
|
||||
class Iap {
|
||||
|
||||
_channel = null;
|
||||
_channelError = null;
|
||||
_productIds = [];
|
||||
|
||||
_ready = false;
|
||||
|
||||
constructor({
|
||||
products
|
||||
}) {
|
||||
this._productIds = products;
|
||||
}
|
||||
|
||||
init() {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.getChannels((channel) => {
|
||||
this._ready = true;
|
||||
resolve(channel);
|
||||
}, (err) => {
|
||||
reject(err);
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
getProduct(productIds) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this._channel.requestProduct(productIds || this._productIds, (res) => {
|
||||
resolve(res);
|
||||
}, (err) => {
|
||||
reject(err);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
requestPayment(orderInfo) {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.requestPayment({
|
||||
provider: 'appleiap',
|
||||
orderInfo: orderInfo,
|
||||
success: (res) => {
|
||||
resolve(res);
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
restoreCompletedTransactions(username) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this._channel.restoreCompletedTransactions({
|
||||
manualFinishTransaction: true,
|
||||
username
|
||||
}, (res) => {
|
||||
resolve(res);
|
||||
}, (err) => {
|
||||
reject(err);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
finishTransaction(transaction) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this._channel.finishTransaction(transaction, (res) => {
|
||||
resolve(res);
|
||||
}, (err) => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getChannels(success, fail) {
|
||||
if (this._channel !== null) {
|
||||
success(this._channel)
|
||||
return
|
||||
}
|
||||
|
||||
if (this._channelError !== null) {
|
||||
fail(this._channelError)
|
||||
return
|
||||
}
|
||||
|
||||
uni.getProvider({
|
||||
service: 'payment',
|
||||
success: (res) => {
|
||||
this._channel = res.providers.find((channel) => {
|
||||
return (channel.id === 'appleiap')
|
||||
})
|
||||
|
||||
if (this._channel) {
|
||||
success(this._channel)
|
||||
} else {
|
||||
this._channelError = {
|
||||
errMsg: 'paymentContext:fail iap service not found'
|
||||
}
|
||||
fail(this._channelError)
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get channel() {
|
||||
return this._channel;
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
Iap,
|
||||
IapTransactionState
|
||||
}
|
||||
133
config/login.js
Normal file
133
config/login.js
Normal file
@@ -0,0 +1,133 @@
|
||||
import store from '@/store';
|
||||
import $http from '@/config/requestConfig'
|
||||
import base from '@/config/baseUrl';
|
||||
// #ifdef H5
|
||||
import { h5Login } from '@/config/html5Utils';
|
||||
// #endif
|
||||
let code = "";
|
||||
let loginStart = true;
|
||||
let userInfo = {
|
||||
token: ""
|
||||
};
|
||||
let lastPageUrl = "";
|
||||
// 微信小程序登录
|
||||
function onLogin(type = "judge",callback) {
|
||||
//判断登录状态
|
||||
if (loginStart) {
|
||||
loginStart = false;
|
||||
const _this = this;
|
||||
let platform;
|
||||
// #ifdef MP-WEIXIN
|
||||
platform = 'weixin';
|
||||
// #endif
|
||||
// #ifdef MP-ALIPAY
|
||||
platform = 'alipay';
|
||||
// #endif
|
||||
// #ifdef MP-BAIDU
|
||||
platform = 'baidu';
|
||||
// #endif
|
||||
uni.login({
|
||||
provider: platform,
|
||||
success: function(loginRes) {
|
||||
if (loginRes.errMsg == 'login:ok') {
|
||||
// 获取用户信息
|
||||
uni.getUserInfo({
|
||||
provider: platform,
|
||||
success: function(infoRes) {
|
||||
let httpData = {
|
||||
wxSmallCode: loginRes.code, //小程序code
|
||||
iv: infoRes.iv, //小程序加密算法的初始向量
|
||||
encryptedData: infoRes.encryptedData //包括敏感数据在内的完整用户信息的加密数据
|
||||
};
|
||||
// store.state.chatScenesInfo里面是小程序二维码附带的信息
|
||||
if(store.state.chatScenesInfo.invite){
|
||||
// 推荐码
|
||||
httpData.invite = store.state.chatScenesInfo.invite;
|
||||
}
|
||||
$http.post('api/open/v1/login', httpData).then(res => {
|
||||
loginStart = true;
|
||||
store.commit('setUserInfo', res);
|
||||
callback && callback();
|
||||
if (res.nullUserInfo) {
|
||||
// 没有绑定过微信的头像或者昵称弹出授权获取头像昵称的弹窗
|
||||
store.commit('setBindUserInfoShow', true);
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: "登录成功"
|
||||
});
|
||||
}
|
||||
}, err => {
|
||||
loginStart = true;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
//判断是否登录(所有端)
|
||||
function judgeLogin(callback, type = "judge"){
|
||||
if(store.state.chatScenesInfo.scene == 1154){
|
||||
uni.showToast({
|
||||
title: '请前往小程序使用完整服务',
|
||||
icon: "none"
|
||||
});
|
||||
} else {
|
||||
let storeUserInfo = store.state.userInfo;
|
||||
if(!storeUserInfo.token){ // nvue页面读取不到vuex里面数据,将取缓存
|
||||
storeUserInfo = uni.getStorageSync("userInfo");
|
||||
}
|
||||
if (type != "force" && storeUserInfo.token) {
|
||||
callback();
|
||||
} else if (storeUserInfo.token && !storeUserInfo.phone) {
|
||||
if (type == "force") {
|
||||
uni.navigateTo({
|
||||
url: '/pages/user/bindPhone'
|
||||
});
|
||||
} else {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "您还未绑定手机号,请先绑定~",
|
||||
confirmText: "去绑定",
|
||||
cancelText: "再逛会",
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
uni.navigateTo({
|
||||
url: '/pages/user/bindPhone'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// #ifdef MP
|
||||
onLogin(type, callback);
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
uni.showModal({
|
||||
title: "登录提示",
|
||||
content: "此时此刻需要您登录喔~",
|
||||
confirmText: "去登录",
|
||||
cancelText: "再逛会",
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
uni.navigateTo({
|
||||
url: "/pages/user/login"
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
h5Login(type, () => {
|
||||
callback();
|
||||
});
|
||||
// #endif
|
||||
}
|
||||
}
|
||||
}
|
||||
export {
|
||||
onLogin,
|
||||
judgeLogin
|
||||
}
|
||||
337
config/requestConfig.js
Normal file
337
config/requestConfig.js
Normal file
@@ -0,0 +1,337 @@
|
||||
import request from "@/uni_modules/zhouWei-request/js_sdk/request";
|
||||
import store from '@/store';
|
||||
import base from '@/config/baseUrl';
|
||||
// #ifdef H5
|
||||
import {
|
||||
h5Login
|
||||
} from '@/config/html5Utils';
|
||||
// #endif
|
||||
// #ifdef MP-WEIXIN
|
||||
import {
|
||||
onLogin
|
||||
} from '@/config/login';
|
||||
// #endif
|
||||
let version_code = '';
|
||||
// #ifdef APP-PLUS
|
||||
import {
|
||||
getCurrentNo
|
||||
} from '@/uni_modules/zhouWei-APPUpdate/js_sdk/appUpdate';
|
||||
setTimeout(() => {
|
||||
getCurrentNo(function(res) {
|
||||
console.log("版本号", res);
|
||||
version_code = res.versionCode;
|
||||
});
|
||||
}, 200);
|
||||
// #endif
|
||||
|
||||
//可以new多个request来支持多个域名请求
|
||||
let $http = new request({
|
||||
//接口请求地址
|
||||
baseUrl: base.baseUrl,
|
||||
//服务器本地上传文件地址
|
||||
fileUrl: base.baseUrl,
|
||||
// 服务器上传图片默认url
|
||||
defaultUploadUrl: "api/common/v1/upload_image",
|
||||
// 服务器上传文件名称
|
||||
defaultFileName: "file",
|
||||
//设置请求头(如果使用报错跨域问题,可能是content-type请求类型和后台那边设置的不一致)
|
||||
header: {
|
||||
// 'Content-Type': 'application/json;charset=UTF-8',
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
// 'project_token': base.projectToken, //项目token(可删除)
|
||||
}
|
||||
});
|
||||
// 添加获取七牛云token的方法
|
||||
$http.getQnToken = function(callback) {
|
||||
//该地址需要开发者自行配置(每个后台的接口风格都不一样)
|
||||
$http.get("api/common/v1/qn_upload").then(data => {
|
||||
/*
|
||||
*接口返回参数:
|
||||
*visitPrefix:访问文件的域名
|
||||
*token:七牛云上传token
|
||||
*folderPath:上传的文件夹
|
||||
*region: 地区 默认为:SCN
|
||||
*/
|
||||
callback({
|
||||
visitPrefix: data.visitPrefix,
|
||||
token: data.token,
|
||||
folderPath: data.folderPath
|
||||
});
|
||||
});
|
||||
}
|
||||
// 添加获取阿里云token的方法
|
||||
$http.getAliToken = function(callback) {
|
||||
//该地址需要开发者自行配置(每个后台的接口风格都不一样)
|
||||
$http.get("api/open/v1/ali_oss_upload").then(data => {
|
||||
/*
|
||||
*接口返回参数:
|
||||
*visitPrefix:访问文件的域名
|
||||
*folderPath:上传的文件夹
|
||||
*accessKeyId: 您的oss的访问ID
|
||||
*accessKeySecret: 您的oss的访问密钥
|
||||
*timeout: 签名过期时间(毫秒)默认1800000
|
||||
*/
|
||||
callback({
|
||||
accessKeyId: data.accessKeyId,
|
||||
accessKeySecret: data.accessKeySecret,
|
||||
visitPrefix: data.visitPrefix,
|
||||
folderPath: data.folderPath,
|
||||
timeout: 1800000
|
||||
});
|
||||
});
|
||||
}
|
||||
//请求开始拦截器
|
||||
$http.requestStart = function(options) {
|
||||
// console.log("请求开始", options);
|
||||
if (options.load && options.data.loadAnimate != 'none') {
|
||||
//打开加载动画
|
||||
store.commit("setLoadingShow", true);
|
||||
}
|
||||
// 图片、视频上传大小限制
|
||||
if (options.method == "FILE") {
|
||||
// 文件最大字节: options.maxSize 可以在调用方法的时候加入参数
|
||||
let maxSize = options.maxSize || '';
|
||||
for (let item of options.files) {
|
||||
if (item.fileType == 'image') {
|
||||
if (maxSize && item.size > maxSize) {
|
||||
setTimeout(() => {
|
||||
uni.showToast({
|
||||
title: "图片过大,请重新上传",
|
||||
icon: "none"
|
||||
});
|
||||
}, 500);
|
||||
return false;
|
||||
}
|
||||
} else if (item.fileType == "video") {
|
||||
if (item.duration < 3) {
|
||||
setTimeout(() => {
|
||||
uni.showToast({
|
||||
title: "视频长度不足3秒,请重新上传",
|
||||
icon: "none"
|
||||
});
|
||||
}, 500);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// #ifdef APP-PLUS
|
||||
// 添加当前版本号
|
||||
if (version_code) {
|
||||
options.header['version_code'] = version_code;
|
||||
}
|
||||
// #endif
|
||||
//请求前加入token
|
||||
let storeUserInfo = store.state.userInfo;
|
||||
if (!storeUserInfo) { // nvue页面读取不到vuex里面数据,将取缓存
|
||||
storeUserInfo = uni.getStorageSync("userInfo");
|
||||
}
|
||||
if (storeUserInfo.token) {
|
||||
options.header['token'] = storeUserInfo.token;
|
||||
};
|
||||
return options;
|
||||
}
|
||||
//请求结束
|
||||
$http.requestEnd = function(options) {
|
||||
//判断当前接口是否需要加载动画
|
||||
if (options.load) {
|
||||
// 关闭加载动画
|
||||
store.commit("setLoadingShow", false);
|
||||
}
|
||||
}
|
||||
let loginPopupNum = 0;
|
||||
//所有接口数据处理(此方法需要开发者根据各自的接口返回类型修改,以下只是模板)
|
||||
$http.dataFactory = async function(res) {
|
||||
// console.log("接口请求数据", {
|
||||
// url: res.url,
|
||||
// resolve: res.response,
|
||||
// header: res.header,
|
||||
// data: res.data,
|
||||
// method: res.method,
|
||||
// });
|
||||
if (res.response.statusCode && res.response.statusCode == 200) {
|
||||
let httpData = res.response.data;
|
||||
if (typeof(httpData) == "string") {
|
||||
httpData = JSON.parse(httpData);
|
||||
}
|
||||
/*********以下只是模板(及共参考),需要开发者根据各自的接口返回类型修改*********/
|
||||
|
||||
//判断数据是否请求成功
|
||||
if (httpData.success || httpData.code == 0) {
|
||||
// 返回正确的结果(then接受数据)
|
||||
return Promise.resolve(httpData);
|
||||
} else if (httpData.code == "401") {
|
||||
// token失效
|
||||
if (uni.getStorageSync('guidePages') == 2) {
|
||||
uni.showToast({
|
||||
title: '登录失效,请重新登录',
|
||||
icon: 'none'
|
||||
});
|
||||
console.log('到这里了')
|
||||
setTimeout(() => {
|
||||
uni.navigateTo({
|
||||
url: "/pages/user/login"
|
||||
});
|
||||
}, 10);
|
||||
}
|
||||
|
||||
} else if (httpData.code == "1000" || httpData.code == "1001" || httpData.code == 1100 || httpData
|
||||
.code == 402) {
|
||||
|
||||
// 失败重新请求(最多重新请求3次)
|
||||
// if(res.resend < 3){
|
||||
// let result = await $http.request({
|
||||
// url: res.url,
|
||||
// data: res.data,
|
||||
// method: res.method,
|
||||
// header: res.header,
|
||||
// isPrompt: res.isPrompt,//(默认 true 说明:本接口抛出的错误是否提示)
|
||||
// load: res.load,//(默认 true 说明:本接口是否提示加载动画)
|
||||
// isFactory: res.isFactory, //(默认 true 说明:本接口是否调用公共的数据处理方法,设置false后isPrompt参数将失去作用)
|
||||
// resend: res.resend += 1 // 当前重发次数
|
||||
// });
|
||||
// // 返回正确的结果(then接受数据)
|
||||
// return Promise.resolve(result);
|
||||
// }
|
||||
// 返回错误的结果(catch接受数据)
|
||||
// return Promise.reject({
|
||||
// statusCode: 0,
|
||||
// errMsg: "【request】" + (httpData.info || httpData.msg)
|
||||
// });
|
||||
|
||||
//----------------------------------------分割线---------------------------------------------------
|
||||
|
||||
// 刷新token在重新请求(最多重新请求2次)
|
||||
// if(res.resend < 2){
|
||||
// let tokenResult = await $http.request({
|
||||
// url: "http://localhost:7001/api/common/v1/protocol", // 获取token接口地址
|
||||
// data: {
|
||||
// type: 1000
|
||||
// }, // 获取接口参数
|
||||
// method: "GET",
|
||||
// load: false,//(默认 true 说明:本接口是否提示加载动画)
|
||||
// });
|
||||
// // 储存token
|
||||
// store.commit("userInfo", tokenResult);
|
||||
// let result = await $http.request({
|
||||
// url: res.url,
|
||||
// data: res.data,
|
||||
// method: res.method,
|
||||
// header: res.header,
|
||||
// isPrompt: res.isPrompt,//(默认 true 说明:本接口抛出的错误是否提示)
|
||||
// load: res.load,//(默认 true 说明:本接口是否提示加载动画)
|
||||
// isFactory: res.isFactory, //(默认 true 说明:本接口是否调用公共的数据处理方法,设置false后isPrompt参数将失去作用)
|
||||
// resend: res.resend += 1 // 当前重发次数
|
||||
// });
|
||||
// // 返回正确的结果(then接受数据)
|
||||
// return Promise.resolve(result);
|
||||
// }
|
||||
// 返回错误的结果(catch接受数据)
|
||||
// return Promise.reject({
|
||||
// statusCode: 0,
|
||||
// errMsg: "【request】" + (httpData.info || httpData.msg)
|
||||
// });
|
||||
|
||||
|
||||
store.commit("emptyUserInfo");
|
||||
// #ifdef MP-WEIXIN
|
||||
onLogin();
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
h5Login("force");
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
var content = '此时此刻需要您登录喔~';
|
||||
if (httpData.code == "1000") {
|
||||
content = '此时此刻需要您登录喔';
|
||||
}
|
||||
if (loginPopupNum <= 0) {
|
||||
loginPopupNum++;
|
||||
uni.showModal({
|
||||
title: '温馨提示',
|
||||
content: content,
|
||||
confirmText: "去登录",
|
||||
cancelText: "再逛会",
|
||||
success: function(res) {
|
||||
loginPopupNum--;
|
||||
if (res.confirm) {
|
||||
uni.navigateTo({
|
||||
url: "/pages/user/login"
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// #endif
|
||||
// 返回错误的结果(catch接受数据)
|
||||
return Promise.reject({
|
||||
statusCode: 0,
|
||||
errMsg: "【request】" + (httpData.info || httpData.msg),
|
||||
data: res.data
|
||||
});
|
||||
} else if (httpData.code == "1004") {
|
||||
if (loginPopupNum <= 0) {
|
||||
loginPopupNum++;
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "您还未绑定手机号,请先绑定~",
|
||||
confirmText: "去绑定",
|
||||
cancelText: "再逛会",
|
||||
success: (res) => {
|
||||
loginPopupNum--;
|
||||
if (res.confirm) {
|
||||
uni.navigateTo({
|
||||
url: '/pages/user/bindPhone'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// 返回错误的结果(catch接受数据)
|
||||
return Promise.reject({
|
||||
statusCode: 0,
|
||||
errMsg: "【request】" + (httpData.info || httpData.msg),
|
||||
data: res.data
|
||||
});
|
||||
} else { //其他错误提示
|
||||
console.log(httpData.info || httpData.msg)
|
||||
if (res.isPrompt && res.data.loadAnimate != 'none') {
|
||||
uni.showToast({
|
||||
title: httpData.info || httpData.msg,
|
||||
icon: "none",
|
||||
duration: 3000
|
||||
});
|
||||
}
|
||||
// 返回错误的结果(catch接受数据)
|
||||
return Promise.reject({
|
||||
statusCode: 0,
|
||||
errMsg: "【request】" + (httpData.info || httpData.msg),
|
||||
data: res.data
|
||||
});
|
||||
}
|
||||
|
||||
/*********以上只是模板(及共参考),需要开发者根据各自的接口返回类型修改*********/
|
||||
|
||||
} else {
|
||||
// 返回错误的结果(catch接受数据)
|
||||
return Promise.reject({
|
||||
statusCode: res.response.statusCode,
|
||||
errMsg: "【request】数据工厂验证不通过",
|
||||
data: res.data
|
||||
});
|
||||
}
|
||||
};
|
||||
// 错误回调
|
||||
$http.requestError = function(e) {
|
||||
// e.statusCode === 0 是参数效验错误抛出的
|
||||
if (e.statusCode === 0) {
|
||||
throw e;
|
||||
} else {
|
||||
console.log(e);
|
||||
// uni.showToast({
|
||||
// title: "网络错误,请检查一下网络",
|
||||
// icon: "none"
|
||||
// });
|
||||
}
|
||||
}
|
||||
export default $http;
|
||||
103
config/socket.js
Normal file
103
config/socket.js
Normal file
@@ -0,0 +1,103 @@
|
||||
import base from '@/config/baseUrl';
|
||||
import store from '@/store';
|
||||
class socket {
|
||||
constructor(options) {
|
||||
//地址
|
||||
this.socketUrl = base.socketUrl;
|
||||
this.socketStart = false;
|
||||
this.monitorSocketError();
|
||||
this.monitorSocketClose();
|
||||
this.socketReceive();
|
||||
}
|
||||
init(callback) {
|
||||
const _this = this;
|
||||
if (base.socketUrl) {
|
||||
if(this.socketStart){
|
||||
console.log('webSocket已经启动了');
|
||||
}else{
|
||||
uni.connectSocket({
|
||||
url: this.socketUrl,
|
||||
method: 'GET'
|
||||
});
|
||||
uni.onSocketOpen((res) => {
|
||||
this.socketStart = true;
|
||||
callback && callback();
|
||||
console.log('WebSocket连接已打开!');
|
||||
});
|
||||
setTimeout(() => {
|
||||
_this.getHeartbeat();
|
||||
}, 5000);
|
||||
}
|
||||
}else{
|
||||
console.log('config/baseUrl socketUrl为空');
|
||||
}
|
||||
}
|
||||
//Socket给服务器发送消息
|
||||
send(data, callback) {
|
||||
const _this = this;
|
||||
if (store.state.userInfo.uid) {
|
||||
data.userUid = store.state.userInfo.uid;
|
||||
}
|
||||
console.log(data);
|
||||
uni.sendSocketMessage({
|
||||
data: JSON.stringify(data),
|
||||
success: () => {
|
||||
callback && callback(true);
|
||||
},
|
||||
fail: () => {
|
||||
callback && callback(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
//Socket接收服务器发送过来的消息
|
||||
socketReceive() {
|
||||
const _this = this;
|
||||
uni.onSocketMessage(function(res) {
|
||||
let data = JSON.parse(res.data);
|
||||
console.log('收到服务器内容:', data);
|
||||
_this.acceptMessage && _this.acceptMessage(data);
|
||||
});
|
||||
}
|
||||
//关闭Socket
|
||||
closeSocket() {
|
||||
uni.closeSocket();
|
||||
_this.socketStart = false;
|
||||
}
|
||||
//监听Socket关闭
|
||||
monitorSocketClose() {
|
||||
const _this = this;
|
||||
uni.onSocketClose(function(res) {
|
||||
console.log('WebSocket 已关闭!');
|
||||
_this.socketStart = false;
|
||||
setTimeout(function() {
|
||||
_this.init();
|
||||
}, 3000);
|
||||
});
|
||||
}
|
||||
//监听Socket错误
|
||||
monitorSocketError() {
|
||||
const _this = this;
|
||||
uni.onSocketError(function(res) {
|
||||
_this.socketStart = false;
|
||||
console.log('WebSocket连接打开失败,请检查!');
|
||||
});
|
||||
}
|
||||
//心跳
|
||||
getHeartbeat() {
|
||||
const _this = this;
|
||||
this.send({
|
||||
type: "心跳",
|
||||
userUid: store.state.userInfo.userUid
|
||||
}, (val) => {
|
||||
setTimeout(() => {
|
||||
if (val) {
|
||||
_this.getHeartbeat();
|
||||
} else {
|
||||
_this.init();
|
||||
}
|
||||
}, 10000);
|
||||
});
|
||||
}
|
||||
};
|
||||
const mySocket = new socket();
|
||||
export default mySocket;
|
||||
310
config/utils.js
Normal file
310
config/utils.js
Normal file
@@ -0,0 +1,310 @@
|
||||
import $http from '@/config/requestConfig'
|
||||
import store from '@/store';
|
||||
import base from '@/config/baseUrl';
|
||||
import {
|
||||
getAppWxLatLon
|
||||
} from '@/plugins/utils';
|
||||
// #ifdef H5
|
||||
import {
|
||||
getLatLonH5,
|
||||
publicShareFun,
|
||||
wxPublicPay,
|
||||
getBrowser,
|
||||
appMutual
|
||||
} from '@/config/html5Utils';
|
||||
// 公众号分享
|
||||
export const publicShare = publicShareFun;
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
import appShareFun, {
|
||||
closeShare
|
||||
} from '@/uni_modules/zhouWei-APPshare/js_sdk/appShare';
|
||||
// APP分享
|
||||
export const appShare = function(data, callbcak) {
|
||||
let userInfo = store.state.userInfo;
|
||||
if (!(userInfo && userInfo.uid)) {
|
||||
userInfo = uni.getStorageSync("userInfo");
|
||||
}
|
||||
let shareData = {
|
||||
shareTitle: data.shareTitle || base.share.title,
|
||||
shareUrl: data.shareUrl || base.share.link,
|
||||
shareContent: data.shareContent || base.share.desc,
|
||||
shareImg: data.shareImg || base.share.imgUrl,
|
||||
}
|
||||
if (userInfo && userInfo.uid) {
|
||||
if (data.shareUrl) {
|
||||
if (data.shareUrl.indexOf("?") >= 0) {
|
||||
shareData.shareUrl = data.shareUrl + "&recommend=" + userInfo.uid
|
||||
} else {
|
||||
shareData.shareUrl = data.shareUrl + "?recommend=" + userInfo.uid
|
||||
}
|
||||
} else if (base.share && base.share.link) {
|
||||
if (base.share.link.indexOf("?") >= 0) {
|
||||
shareData.shareUrl = base.share.link + "&recommend=" + userInfo.uid
|
||||
} else {
|
||||
shareData.shareUrl = base.share.link + "?recommend=" + userInfo.uid
|
||||
}
|
||||
}
|
||||
}
|
||||
return appShareFun({
|
||||
shareTitle: data.shareTitle || base.share.title,
|
||||
shareUrl: data.shareUrl || base.share.link,
|
||||
shareContent: data.shareContent || base.share.desc,
|
||||
shareImg: data.shareImg || base.share.imgUrl,
|
||||
}, callbcak);
|
||||
};
|
||||
export const closeAppShare = closeShare;
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
// 微信小程序分享
|
||||
export const wxShare = function(data = {}) {
|
||||
let shareInfo = {
|
||||
title: data.title || base.share.title,
|
||||
};
|
||||
if (data.path && typeof(data.path) == "string") {
|
||||
shareInfo.path = data.path;
|
||||
} else if (data.path != 1) {
|
||||
shareInfo.path = "pages/home/home";
|
||||
}
|
||||
if (data.imageUrl) {
|
||||
shareInfo.imageUrl = data.imageUrl;
|
||||
}
|
||||
let userInfo = store.state.userInfo;
|
||||
if (!(userInfo && userInfo.uid)) {
|
||||
userInfo = uni.getStorageSync("userInfo");
|
||||
}
|
||||
if (userInfo && userInfo.uid) {
|
||||
if (data.query && typeof(data.query) == "object") {
|
||||
data.query.recommendCode = userInfo.uid;
|
||||
} else {
|
||||
data.query = {
|
||||
recommendCode: userInfo.uid
|
||||
};
|
||||
}
|
||||
}
|
||||
if (data.query && typeof(data.query) == "object") {
|
||||
Object.keys(data.query).forEach((key, index) => {
|
||||
if (index > 0 && shareInfo.query) {
|
||||
shareInfo.query += "&" + key + "=" + data.query[key];
|
||||
shareInfo.path += "&" + key + "=" + data.query[key];
|
||||
} else {
|
||||
shareInfo.query = key + "=" + data.query[key];
|
||||
shareInfo.path += "?" + key + "=" + data.query[key];
|
||||
}
|
||||
});
|
||||
}
|
||||
return shareInfo;
|
||||
}
|
||||
// #endif
|
||||
|
||||
//支付(APP微信支付、APP支付宝支付、微信小程序支付)
|
||||
export const setPay = function(payInfo, callback) {
|
||||
console.log(payInfo)
|
||||
payInfo.customerId = store.state.userInfo.id
|
||||
let httpUrl = "";
|
||||
if (payInfo.typePay == 'wxpay') {
|
||||
// APP微信支付
|
||||
httpUrl = '/v3/pay/placeAnOrder/app'
|
||||
} else if (payInfo.typePay == 'alipay') {
|
||||
// APP支付宝支付
|
||||
httpUrl = 'pay/aliPay/pay'
|
||||
} else if (payInfo.typePay == 'smallPay') {
|
||||
// 微信小程序支付
|
||||
httpUrl = 'api/pay/v1/small_pay_sign_wx'
|
||||
}else if(payInfo.typePay == 'appleiap'){
|
||||
// 苹果支付
|
||||
}
|
||||
$http.post(httpUrl, payInfo).then(data => {
|
||||
console.log(data,'data')
|
||||
let payData = {
|
||||
success: function(res) {
|
||||
callback && callback({
|
||||
success: true,
|
||||
data: res
|
||||
});
|
||||
console.log('success:' + JSON.stringify(res));
|
||||
},
|
||||
fail: function(err) {
|
||||
callback && callback({
|
||||
success: false,
|
||||
data: err
|
||||
});
|
||||
console.log('fail:' + JSON.stringify(err));
|
||||
}
|
||||
};
|
||||
if (payInfo.typePay == 'smallPay') {
|
||||
// 小程序
|
||||
payData.provider = 'wxpay';
|
||||
payData.timeStamp = data.timeStamp;
|
||||
payData.nonceStr = data.nonceStr;
|
||||
payData.package = data.package;
|
||||
// payData.package = "prepay_id=" + data.prepayid;
|
||||
payData.signType = "MD5";
|
||||
payData.paySign = data.sign;
|
||||
} else if (payInfo.typePay == 'wxpay') {
|
||||
// app微信
|
||||
payData.provider = 'wxpay';
|
||||
payData.orderInfo = data;
|
||||
} else if (payInfo.typePay == 'alipay') {
|
||||
// app 支付宝
|
||||
payData.provider = 'alipay';
|
||||
payData.orderInfo = data.orderInfo;
|
||||
} else if (payInfo.typePay == 'baidu') {
|
||||
payData.provider = 'baidu';
|
||||
payData.orderInfo = data;
|
||||
}
|
||||
|
||||
if (payData.orderInfo != '' && payData.orderInfo != undefined) {
|
||||
console.log("支付参数", payData);
|
||||
// let EnvUtils = plus.android.importClass('com.alipay.sdk.app.EnvUtils');
|
||||
// EnvUtils.setEnv(EnvUtils.EnvEnum.SANDBOX);
|
||||
uni.requestPayment(payData);
|
||||
}
|
||||
|
||||
}, err => {
|
||||
callback && callback({
|
||||
success: false,
|
||||
data: err
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 支付统一分配
|
||||
export const setPayAssign = function(orderInfo, callback) {
|
||||
orderInfo.price = orderInfo.price || orderInfo.pricePay;
|
||||
orderInfo.title = orderInfo.title || orderInfo.orderTitle;
|
||||
//支付
|
||||
// #ifdef APP-PLUS
|
||||
uni.navigateTo({
|
||||
url: '/pages/home/weChatPay?orderNo=' + orderInfo.orderNo + '&price=' + orderInfo.price +
|
||||
'&title=' + orderInfo.title
|
||||
});
|
||||
// #endif
|
||||
// #ifdef MP-WEIXIN
|
||||
setPay({
|
||||
...orderInfo,
|
||||
type: "smallPay"
|
||||
}, res => {
|
||||
if (res.success) {
|
||||
uni.redirectTo({
|
||||
url: "/pages/shopCar/paySuccess?orderNo=" + orderInfo.orderNo
|
||||
});
|
||||
}
|
||||
});
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
if (getBrowser() === '微信') {
|
||||
wxPublicPay({
|
||||
orderNo: orderInfo.orderNo
|
||||
}, function() {
|
||||
uni.redirectTo({
|
||||
url: "/pages/shopCar/paySuccess?orderNo=" + orderInfo.orderNo
|
||||
});
|
||||
});
|
||||
} else {
|
||||
appMutual('setJumpPay', orderInfo);
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
// 获取地址信息 (微信小程序、APP、公众号)
|
||||
export const getLatLon = function(tip) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const successProcess = function(res) {
|
||||
store.commit("setCurrentAddress", {
|
||||
latitude: res.latitude,
|
||||
longitude: res.longitude
|
||||
});
|
||||
resolve(res);
|
||||
};
|
||||
const errProcess = function(err) {
|
||||
reject(err);
|
||||
if (tip) {
|
||||
uni.showToast({
|
||||
title: err,
|
||||
icon: "none"
|
||||
});
|
||||
}
|
||||
};
|
||||
// #ifdef H5
|
||||
getLatLonH5(successProcess, errProcess);
|
||||
// #endif
|
||||
// #ifndef H5
|
||||
getAppWxLatLon(successProcess, errProcess);
|
||||
// #endif
|
||||
});
|
||||
}
|
||||
|
||||
// 查看是否有某本书的权限
|
||||
export const checkBookRight = function(data,callback) {
|
||||
console.log('接受的值', data)
|
||||
$http.request({
|
||||
url: "/book/user/checkUserBook",
|
||||
method: "POST", // POST、GET、PUT、DELETE,具体说明查看官方文档
|
||||
data:data,
|
||||
header: { //默认 无 说明:请求头1
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
}).then(res => {
|
||||
// console.log(res,'checkBookRight')
|
||||
if(res.code === 0){
|
||||
callback && callback({
|
||||
success: true,
|
||||
data: '有权限'
|
||||
});
|
||||
}
|
||||
}).catch(e => {
|
||||
callback && callback({
|
||||
success: false,
|
||||
data: '无权限'
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
// 单独微信支付
|
||||
export const setWXPay = function(payInfo, callback) {
|
||||
$http.request({
|
||||
url: "/pay/placeAnOrder/shoppingPay",
|
||||
method: "POST", // POST、GET、PUT、DELETE,具体说明查看官方文档
|
||||
data:payInfo,
|
||||
header: { //默认 无 说明:请求头1
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
}).then(res => {
|
||||
console.log(res,'resshoppingPay')
|
||||
if(res.code === 0){
|
||||
let payData = {
|
||||
provider : 'wxpay',
|
||||
orderInfo: {
|
||||
"appid": res.paramMap.appid , // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
|
||||
"noncestr": res.Map.noncestr, // 随机字符串
|
||||
"package": res.Map.package, // 固定值
|
||||
"partnerid": res.paramMap.mchid, // 微信支付商户号
|
||||
"prepayid": res.Map.prepayid, // 统一下单订单号
|
||||
"timestamp": res.Map.timestamp, // 时间戳(单位:秒)
|
||||
"signType": "SHA256-RSA",
|
||||
"sign": res.Map.sign
|
||||
},
|
||||
success(res) {
|
||||
callback && callback({
|
||||
success: true,
|
||||
data: res
|
||||
});
|
||||
console.log('success:' + JSON.stringify(res));
|
||||
},
|
||||
fail(err) {
|
||||
callback && callback({
|
||||
success: false,
|
||||
data: err
|
||||
});
|
||||
console.log('fail:' + JSON.stringify(err));
|
||||
|
||||
}
|
||||
}
|
||||
// console.log(payData)
|
||||
if(payData.orderInfo.prepayid != '' && payData.orderInfo.prepayid != undefined){
|
||||
uni.requestPayment(payData);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user