Skip to content

Commit

Permalink
修改成无需自己搭建后台即可完美运行
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenth520 committed Sep 20, 2017
1 parent f4328d0 commit 95690ad
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 37 deletions.
46 changes: 14 additions & 32 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//app.js
var util = require('utils/util.js');
App({

onLaunch: function () {
Expand All @@ -10,21 +11,12 @@ App({
key: 'sk',
success: function(res) {
var sk = res.data;
wx.request({
url: 'https://xcx.codems.cn/api/user/vaild_sk',
data: {
"sk":sk
},
method: 'POST',
header: {'Content-Type':'application/x-www-form-urlencoded'},
success:function(data){
if(data.data.status == 1){
that.globalData.sk = sk;
}else{
that.login();
return;
}

util.req('user/vaild_sk', { "sk": sk }, function (data) {
if (data.status == 1) {
that.globalData.sk = sk;
} else {
that.login();
return;
}
})
},
Expand Down Expand Up @@ -58,23 +50,13 @@ App({
success: function (res) {
wx.getUserInfo({
success: function(userinfo){
wx.request({
url: 'https://xcx.codems.cn/api/user/login',
data: {
"code":res.code,
"encryptedData":userinfo.encryptedData,
"iv":userinfo.iv
},
method: 'POST',
header: {
'Content-type':'application/json'
},
success:function(data){
data = data.data;
console.log(data);
that.setUserInfo(data.user);
that.setSk(data.sk);
}
util.req('user/login', {
"code": res.code,
"encryptedData": userinfo.encryptedData,
"iv": userinfo.iv
}, function (data) {
that.setUserInfo(data.user);
that.setSk(data.sk);
})
},
fail: function(res) {
Expand Down
19 changes: 14 additions & 5 deletions utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ function formatNumber(n) {
n = n.toString()
return n[1] ? n : '0' + n
}


var rootDocment = 'https://xcx.codems.cn/api/';

var rootDocment = 'https://xcx.codems.cn/api/';
function req(url,data,cb){
//修改成你的appid及appsecret
var AppConf = {'appid':'wx0aa456241abc9e8e', 'appsecret':'76b24dc34ae91aa5fe89b7dc4413e981'};

function req(url, data, cb) {
data.appid = AppConf.appid;
data.appsecret = AppConf.appsecret;
wx.request({
url: rootDocment + url,
data: data,
Expand All @@ -31,10 +38,12 @@ function req(url,data,cb){
})
}

function getReq(url,data,cb){
function getReq(url,data,cb){
data.appid = AppConf.appid;
data.appsecret = AppConf.appsecret;
wx.request({
url: rootDocment + url,
data: data,
url: rootDocment + url,
data: data,
method: 'get',
header: {'Content-Type':'application/x-www-form-urlencoded'},
success: function(res){
Expand Down

0 comments on commit 95690ad

Please sign in to comment.