diff --git a/public/assets/wechat/app.html b/public/assets/wechat/app.html index ef8e06d64..d2eebb0b8 100644 --- a/public/assets/wechat/app.html +++ b/public/assets/wechat/app.html @@ -19,6 +19,7 @@ + diff --git a/public/javascripts/wechat/app.js b/public/javascripts/wechat/app.js index b9f2a50e8..759224d14 100644 --- a/public/javascripts/wechat/app.js +++ b/public/javascripts/wechat/app.js @@ -1,18 +1,16 @@ -var app = angular.module('wechat', ['ngRoute']); -var apiUrl = 'http://localhost:3000/api/v1/'; -//var openid= "oCnvgvz8R7QheXE-R9Kkr39j8Ndg"; -var openid = ''; -var debug = true; //调试标志,如果在本地请置为true +var app = angular.module('wechat', ['ngRoute','ngCookies']); +var apiUrl = 'http://wechat.trustie.net/api/v1/'; +var debug = false; //调试标志,如果在本地请置为true -if(debug===true){ - openid = "1"; -} +app.factory('auth', function($http,$routeParams, $cookies){ + var _openid = ''; -app.factory('auth', function($http,$routeParams){ - var _openid = openid; + if(debug===true){ + _openid = "oCnvgvz8R7QheXE-R9Kkr39j8Ndg"; + } var getOpenId = function(cb) { - if (_openid.length > 0) { + if (typeof _openid !== 'undefined' && _openid.length > 0) { cb(_openid); return; } @@ -23,19 +21,26 @@ app.factory('auth', function($http,$routeParams){ method: 'POST' }).then(function successCallback(response) { _openid = response.data.openid; - openid = _openid; + if(typeof _openid !== 'undefined' && _openid.length>0){ + if(debug !== true){ //如果是生产环境,就存到cookies中 + $cookies.put("openid", _openid); + } + } else { + if(debug!==true){//考虑从cookies中取出 + _openid = $cookies.get('openid'); + } + } + cb(_openid); }, function errorCallback(response) { cb(null); }); }; - - - var setOpenId = function(id){ - _openid = id; + var openid = function(){ + return _openid; } - return {getOpenId: getOpenId, setOpenId: setOpenId}; + return {getOpenId: getOpenId, openid: openid}; }); app.controller('ActivityController',function($scope, $http, auth){ @@ -43,6 +48,8 @@ app.controller('ActivityController',function($scope, $http, auth){ return "http://www.trustie.net/" + url; } + console.log("ActivityController load"); + $scope.activities = []; $scope.page = 1; @@ -51,7 +58,7 @@ app.controller('ActivityController',function($scope, $http, auth){ $http({ method: 'POST', url: apiUrl+ "activities", - data: {openid: openid, page: page}, + data: {openid: auth.openid(), page: page}, }).then(function successCallback(response) { $scope.activities = $scope.activities.concat(response.data.data); }, function errorCallback(response) { @@ -98,7 +105,7 @@ app.controller('IssueController', function($scope, $http, $routeParams, auth){ var userInfo = { type: "Issue", content: data.comment, - openid: openid, + openid: auth.openid(), }; $http({