|
- // pages/index/index.js
- import * as UTIL from '../../../utils/util.js';
- import * as API from '../../../utils/API.js';
- import * as STORAGE from '../../../utils/storage'
- const APP = getApp();
- Page({
- data: {
- isIPhoneX:false,
- privacyCheck:true //用户协议
- },
- onLoad: function (options) {
- this.setData({
- isIPhoneX:UTIL.isIPhoneX()
- })
- this.automaticLogin()
- },
- //自动登录
- automaticLogin(){
- let automatic = STORAGE.getToken();
- let getOpenId = STORAGE.getOpenId();
- if(automatic == '' && getOpenId ==''){
- UTIL.getCOdeFromWX({
- complate: (code) => {
- let sendData = {
- code: code
- }
- UTIL.httpRequestNoneDetal(API.URL_GET_OPENID, sendData, "POST", {
- success: (res) => {
- if (res.code == API.SUCCESS_CODE) {
- wx.navigateTo({
- url: '/pages/index/index',
- })
- }
- }
- })
- }
- });
- }else{
- wx.navigateTo({
- url: '/pages/index/index',
- })
- }
- },
- //用户隐私协议选项
- checkboxChange: function(res) {
- let checkStatus = false;
- if(res.detail.value.length!=0){
- checkStatus = true;
- }else{
- checkStatus = false;
- }
- this.setData({
- privacyCheck:checkStatus
- })
- },
- //微信一键登录授权
- getPhoneNumber: function(res) {
- let that = this;
- let {
- detail
- } = res;
- if (!detail.encryptedData) {
- //允许授权
- APP.showToast("未获取到手机号码,注册失败!");
- return;
- }else if(this.data.privacyCheck == false){
- APP.showToast("请阅读并同意用户协议和隐私政策!");
- return;
- }
- let sendData = {
- sessionKey:STORAGE.getSessionKey(),
- iv:detail.iv,
- encryptedData:detail.encryptedData
- }
- UTIL.httpRequest(API.URL_POST_DECRYPTEDWXDATA, sendData,{
- success: (res) => {
- if (res.code == API.SUCCESS_CODE) {
- let phoneNumber = res.data.phoneNumber;
- //微信手机号码绑定
- that.wxUserBand(phoneNumber)
- // UTIL.showToastNoneIcon("数据共:" + res._data.length + "条");
- } else {
- //待删
-
- UTIL.showToastNoneIcon(res.msg)
- }
- },
- fail: (res) => {
- UTIL.showToastNoneIcon(API.MSG_FAIL_HTTP)
- }
- });
- },
- wxUserBand(phone){
- let sendData = {
- openId:STORAGE.getOpenId(),
- phonenumber:phone
- }
- UTIL.httpRequest(API.URL_POST_USERBAND, sendData,{
- success: (res) => {
- if (res.code == API.SUCCESS_CODE) {
- wx.navigateTo({
- url: '/pages/index/index',
- })
- }else{
- UTIL.showToastNoneIcon(res.msg)
- }
- },
- fail: (res) => {
- UTIL.showToastNoneIcon(API.MSG_FAIL_HTTP)
- }
- });
- console.log(sendData)
- //
- }
-
- })
|