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.
 

106 lines
3.1 KiB

// pages/startImage/startImage.js
var app = getApp();
var network = require("../../utils/net.js");
var getOpenIdByCode = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/GetMiniOpenIdByCode';
var getBindCustomer = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/GetBindCustomer';
var getCookie = '/MainSystem/MainSystem/Auth/WeixinLogin';
var isBindedPath = '/MainSystem/B3MiniProgramRpc/XuRpcs/Employee/AccountRpc/IsBinded';
var isBindWeixinPath = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/IsBindWeixinMP';
Page({
data: {
},
onShow: function() {
var that = this;
wx.login({
success: function(res) {
let code = res.code;
let method = getOpenIdByCode;
let params = [app.globalData.appID, code];
// 获取openID
network.requestLoading(method, params, function(res) {
app.globalData.openID = res.result;
// 获取绑定客户ID及用户电话
that.GetBindCustomer();
})
}
});
},
/**
* 获取绑定客户ID及用户电话 参数1、appID 2、openID
* 返回值globalCustomerID,WeixinUser_Phone
* 成功调用获取cookie方法及判断是否绑定成功方法
*/
GetBindCustomer: function() {
var that = this;
let method = getBindCustomer;
let params = [app.globalData.appID, app.globalData.openID];
network.requestLoading(method, params, function(res) {
if (res.result != null) {
app.globalData.globalCustomerID = res.result.ID;
app.globalData.phoneNum = res.result.WeixinUser_Phone;
// 获取cookie值
that.WeixinLogin(function(res) {
// 判断是否绑定成功 参数openid 返回值phoneNum
that.IsBinded(app.globalData.openID);
});
}
})
},
// 获取cookie值 参数1、appID 2、openID
WeixinLogin: function(successtion) {
var that = this;
let method = getCookie;
let params = [app.globalData.appID, app.globalData.openID];
network.transfer_request(method, params, function(res) {
app.globalData.cookie = res.result;
successtion();
})
},
/**
* 判断是否绑定成功 参数openid
* 返回值phoneNum
* 成功调用是否关注公众号方法
*/
IsBinded: function(openid) {
var that = this;
let method = isBindedPath;
let params = [openid];
network.transfer_request(method, params, function(res) {
if (res.result != "") {
app.globalData.phoneNum = res.result;
// 判断是否关注公众号
that.IsBindWeixinMP(app.globalData.phoneNum)
}
})
},
// 判断是否关注公众号 参数phone 返回值bool 成功进入首页
IsBindWeixinMP: function(phone) {
let method = isBindWeixinPath;
let params = [phone];
network.requestLoading(method, params, function(res) {
// res.result = false;
if (res.result == true) {
wx.switchTab({
url: '/pages/homePage/homePage',
})
} else {
wx.showModal({
title: '提示',
content: '请关注公众号',
showCancel: false,
})
}
})
},
})