Commit 20b4559f by 梁建民

GET

parent 47113b44
...@@ -79,7 +79,6 @@ App({ ...@@ -79,7 +79,6 @@ App({
// 查看是否授权 // 查看是否授权
wx.getSetting({ wx.getSetting({
success(res) { success(res) {
console.log(res)
if (res.authSetting['scope.userInfo']) { if (res.authSetting['scope.userInfo']) {
// 已经授权 // 已经授权
wx.switchTab({ wx.switchTab({
......
...@@ -84,7 +84,7 @@ Page({ ...@@ -84,7 +84,7 @@ Page({
}); });
//获取openId //获取openId
http.getData(apis.getOpenId, { http.getData(apis.getOpenId, 'GET',{
code: res.code, code: res.code,
'userinfo[avatarUrl]': self.data.userinfo.avatarUrl, 'userinfo[avatarUrl]': self.data.userinfo.avatarUrl,
'userinfo[nickName]': self.data.userinfo.nickName 'userinfo[nickName]': self.data.userinfo.nickName
...@@ -110,15 +110,10 @@ Page({ ...@@ -110,15 +110,10 @@ Page({
} }
}, true); }, true);
} else { } else {
console.log('登录失败!' + res.errMsg); console.log('登录失败!' + res.errMsg);
} }
}, },
fail(res) { fail(res) {
wx.showLoading({
title: '网络不通,请重试'
})
} }
}) })
......
const http = require('../../../utils/util.js'); const http = require('../../../utils/util.js');
import { apis } from '../../../utils/api.js'; import {
apis
} from '../../../utils/api.js';
Page({ Page({
...@@ -69,17 +71,15 @@ Page({ ...@@ -69,17 +71,15 @@ Page({
* 一键获取手机号 * 一键获取手机号
*/ */
getPhoneNumber(e) { getPhoneNumber(e) {
if (e.detail.errMsg == 'getPhoneNumber:ok'){ if (e.detail.errMsg == 'getPhoneNumber:ok') {
http.getData(apis.getwxUserInfo, { http.getData(apis.getwxUserInfo, 'GET', {
openid: wx.getStorageSync('openid'), openid: wx.getStorageSync('openid'),
session_key: wx.getStorageSync('session_key'), session_key: wx.getStorageSync('session_key'),
encryptedData: e.detail.encryptedData, encryptedData: e.detail.encryptedData,
iv: e.detail.iv iv: e.detail.iv
}, function (res) { }, (res) => {
if (res.err_code === 0) { if (res.err_code === 0) {
//注入token //注入token
wx.setStorage({ wx.setStorage({
key: "access_token", key: "access_token",
...@@ -89,18 +89,14 @@ Page({ ...@@ -89,18 +89,14 @@ Page({
wx.switchTab({ wx.switchTab({
url: '/pages/tab/home/home' url: '/pages/tab/home/home'
}); });
} }
},true); }, true);
}else{
} else {
//用户拒绝获取手机 //用户拒绝获取手机
wx.navigateTo({ wx.navigateTo({
url: '/pages/person/login/index' url: '/pages/person/login/index'
}); });
} }
} }
}) })
...@@ -210,7 +210,7 @@ Page({ ...@@ -210,7 +210,7 @@ Page({
loading: true loading: true
}); });
http.postData(apis.authlogin, e.detail.value, function (res) { http.getData(apis.authlogin,'POST', e.detail.value, function (res) {
if (res.err_code === 0) { if (res.err_code === 0) {
......
...@@ -130,7 +130,7 @@ Page({ ...@@ -130,7 +130,7 @@ Page({
//是否填写了验证码 //是否填写了验证码
if (this.data.captcha) { if (this.data.captcha) {
http.getData(apis.getRegistCode, { http.getData(apis.getRegistCode,'GET',{
captchaUuid: this.data.captchaUuid, captchaUuid: this.data.captchaUuid,
captcha: this.data.captcha, captcha: this.data.captcha,
mobile: this.data.formData.mobile, mobile: this.data.formData.mobile,
...@@ -186,7 +186,7 @@ Page({ ...@@ -186,7 +186,7 @@ Page({
vcode: true vcode: true
}); });
http.getData(apis.captchaInfo, null, (res) => { http.getData(apis.captchaInfo,'GET',null, (res) => {
this.setData({ this.setData({
captchaUrl: res.captchaUrl, captchaUrl: res.captchaUrl,
captchaUuid: res.captchaUuid captchaUuid: res.captchaUuid
...@@ -354,7 +354,7 @@ Page({ ...@@ -354,7 +354,7 @@ Page({
loading: true loading: true
}); });
http.postData(apis.authRegister, e.detail.value, (res) => { http.getData(apis.authRegister,'POST', e.detail.value, (res) => {
if (res.err_code === 0) { if (res.err_code === 0) {
//注入token //注入token
...@@ -363,10 +363,18 @@ Page({ ...@@ -363,10 +363,18 @@ Page({
data: res.data.access_token data: res.data.access_token
}); });
wx.switchTab({ wx.navigateTo({
url: '/pages/tab/home/home' url: '/pages/person/successfully/index'
}) });
}else if(res.err_code === 500){
//图形验证码不正确的时候
this.refreshVerification();
wx.showToast({
title: res.err_msg,
icon: 'none',
duration: 2000
});
} else { } else {
wx.showToast({ wx.showToast({
title: res.err_msg, title: res.err_msg,
...@@ -374,6 +382,7 @@ Page({ ...@@ -374,6 +382,7 @@ Page({
duration: 2000 duration: 2000
}); });
} }
this.setData({ this.setData({
disabledBtn: false, disabledBtn: false,
loading: false loading: false
......
...@@ -62,5 +62,13 @@ Page({ ...@@ -62,5 +62,13 @@ Page({
*/ */
onShareAppMessage: function () { onShareAppMessage: function () {
},
/**
* 暂不认证
*/
toUrl: function() {
wx.switchTab({
url: '/pages/tab/home/home'
})
} }
}) })
\ No newline at end of file
...@@ -7,5 +7,5 @@ ...@@ -7,5 +7,5 @@
<text class="t2">资质认证</text> <text class="t2">资质认证</text>
<text class="t1">” 否则将影响您的询价和报价业务</text> <text class="t1">” 否则将影响您的询价和报价业务</text>
</view> </view>
<text class="skip-text">暂不认证,跳过</text> <text class="skip-text" bindtap="toUrl">暂不认证,跳过</text>
</view> </view>
...@@ -126,7 +126,7 @@ Page({ ...@@ -126,7 +126,7 @@ Page({
//是否填写了验证码 //是否填写了验证码
if (this.data.captcha) { if (this.data.captcha) {
http.getData(apis.getRegistCode, { http.getData(apis.getRegistCode, 'GET', {
captchaUuid: this.data.captchaUuid, captchaUuid: this.data.captchaUuid,
captcha: this.data.captcha, captcha: this.data.captcha,
mobile: this.data.formData.mobile, mobile: this.data.formData.mobile,
...@@ -182,7 +182,7 @@ Page({ ...@@ -182,7 +182,7 @@ Page({
vcode: true vcode: true
}); });
http.getData(apis.captchaInfo, null, (res) => { http.getData(apis.captchaInfo, 'GET', null, (res) => {
this.setData({ this.setData({
captchaUrl: res.captchaUrl, captchaUrl: res.captchaUrl,
captchaUuid: res.captchaUuid captchaUuid: res.captchaUuid
...@@ -304,7 +304,7 @@ Page({ ...@@ -304,7 +304,7 @@ Page({
loading: true loading: true
}); });
http.postData(apis.authMobilelogin, e.detail.value, (res) => { http.getData(apis.authMobilelogin, 'POST', e.detail.value, (res) => {
if (res.err_code === 0) { if (res.err_code === 0) {
//注入token //注入token
...@@ -317,6 +317,14 @@ Page({ ...@@ -317,6 +317,14 @@ Page({
url: '/pages/tab/home/home' url: '/pages/tab/home/home'
}) })
} else if (res.err_code === 500) {
//图形验证码不正确的时候
this.refreshVerification();
wx.showToast({
title: res.err_msg,
icon: 'none',
duration: 2000
});
} else { } else {
wx.showToast({ wx.showToast({
title: res.err_msg, title: res.err_msg,
......
...@@ -12,6 +12,10 @@ const apis = { ...@@ -12,6 +12,10 @@ const apis = {
*/ */
getOpenId: auth_url + '/v1/getOpenId', getOpenId: auth_url + '/v1/getOpenId',
/** /**
* 刷新token
*/
authRefresh: auth_url + '/auth/refresh',
/**
* 获取微信用户信息 * 获取微信用户信息
*/ */
getwxUserInfo: auth_url + '/v1/getwxUserInfo', getwxUserInfo: auth_url + '/v1/getwxUserInfo',
......
//数据请求(get) import {
const getData = (url, param, callBack,loading) => { apis
wx.showNavigationBarLoading(); } from './api.js';
var params = Object.assign({}, param, { source: 1 });
if(loading){
wx.showLoading();
}
wx.request({
url: url,
data: params,
header: {
"Content-Type": "applciation/json"
},
success: (res) => {
typeof callBack == "function" && callBack(res.data, "");
wx.hideNavigationBarLoading();
wx.hideLoading();
},
fail: (err) => {
typeof callBack == "function" && callBack(null, err.errMsg);
console.log(err);
wx.hideNavigationBarLoading(); //数据请求(get,post)
const getData = (url, type, param, callBack, loading, isheader) => {
wx.hideLoading(); wx.showNavigationBarLoading();
//获取token
var token, header;
wx.getStorage({
key: 'access_token',
success(res) {
if (res.data) {
token = res.data;
} }
}) }
}; });
//数据请求(post)
const postData = (url, param, callBack, loading) => {
wx.showNavigationBarLoading();
var params = Object.assign({}, param, { source: 1 }); //参数字段追加来源字段
var params = Object.assign({}, param, {
source: 1
});
//是否启用loading加载效果
if (loading) { if (loading) {
wx.showLoading(); wx.showLoading();
} }
//是否启用请求头token
if (isheader) {
header = {
"Content-Type": "applciation/json",
"Authorization": 'Bearer ' + token
}
} else {
header = {
"Content-Type": "applciation/json"
}
}
wx.request({ wx.request({
url: url, url: url,
data: params, data: params,
header: { header: header,
"Content-Type": "applciation/json" method: type,
},
method: "POST",
success: (res) => { success: (res) => {
//处理token失效的情况
if (res.data.hasOwnProperty('data')) {
if (res.data.data.err_code === 501 || res.data.data.errcode === 501) {
wx.navigateTo({
url: '/pages/person/login/index'
});
} else {
typeof callBack == "function" && callBack(res.data, ""); typeof callBack == "function" && callBack(res.data, "");
}
} else {
typeof callBack == "function" && callBack(res.data, "");
}
wx.hideNavigationBarLoading(); wx.hideNavigationBarLoading();
wx.hideLoading(); wx.hideLoading();
}, },
fail: (err) => { fail: (err) => {
...@@ -126,6 +127,5 @@ const chooseImg = (num, callback) => { ...@@ -126,6 +127,5 @@ const chooseImg = (num, callback) => {
module.exports = { module.exports = {
getData: getData, getData: getData,
postData: postData,
chooseImg: chooseImg chooseImg: chooseImg
} }
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 sign in to comment