Authored by 姜枫

upate alipay login

@@ -43,13 +43,10 @@ function paramsToRaw(params) { @@ -43,13 +43,10 @@ function paramsToRaw(params) {
43 function AlipayStrategy(options, verify) { 43 function AlipayStrategy(options, verify) {
44 if (typeof options === 'function') { 44 if (typeof options === 'function') {
45 verify = options; 45 verify = options;
46 - options = {};  
47 } 46 }
48 - options = options || {};  
49 passport.Strategy.call(this); 47 passport.Strategy.call(this);
50 this.name = 'alipay'; 48 this.name = 'alipay';
51 this._verify = verify; 49 this._verify = verify;
52 - this._options = options;  
53 } 50 }
54 51
55 util.inherits(AlipayStrategy, passport.Strategy); 52 util.inherits(AlipayStrategy, passport.Strategy);
@@ -63,34 +60,33 @@ AlipayStrategy.prototype.authenticate = function(req, options) { @@ -63,34 +60,33 @@ AlipayStrategy.prototype.authenticate = function(req, options) {
63 60
64 delete query.sign_type; 61 delete query.sign_type;
65 delete query.sign; 62 delete query.sign;
66 - let signString = paramsToRaw(query) + this._options.key; 63 + let signString = paramsToRaw(query) + options.key;
67 64
68 if (signType === 'MD5' && sign !== md5(signString)) { 65 if (signType === 'MD5' && sign !== md5(signString)) {
69 this.error('alipay callback sign check fail'); 66 this.error('alipay callback sign check fail');
70 this.fail('alipay callback sign check fail'); 67 this.fail('alipay callback sign check fail');
  68 + return;
71 } 69 }
72 70
73 if (req.query.is_success === 'T') { 71 if (req.query.is_success === 'T') {
74 let user = { 72 let user = {
75 userId: req.query.user_id, 73 userId: req.query.user_id,
76 - realName: req.query.real_name, 74 + realName: req.query.realName,
77 email: req.query.email 75 email: req.query.email
78 }; 76 };
79 - 77 +
80 this.success(user, null); 78 this.success(user, null);
81 } else { 79 } else {
82 this.error('alipay login fail'); 80 this.error('alipay login fail');
83 this.fail(req.error_code); 81 this.fail(req.error_code);
84 } 82 }
85 } else { 83 } else {
86 - let params = _.assign(defaultOptions, this._options, options); 84 + let params = _.assign(defaultOptions, options);
87 let signType = params.sign_type; 85 let signType = params.sign_type;
88 - let key = params.key;  
89 86
90 delete params.sign_type; 87 delete params.sign_type;
91 delete params.sign; 88 delete params.sign;
92 - delete params.key;  
93 - let signString = paramsToRaw(params) + key; 89 + let signString = paramsToRaw(params) + options.key;
94 90
95 if (signType === 'MD5') { 91 if (signType === 'MD5') {
96 params.sign = md5(signString); 92 params.sign = md5(signString);
@@ -103,4 +99,3 @@ AlipayStrategy.prototype.authenticate = function(req, options) { @@ -103,4 +99,3 @@ AlipayStrategy.prototype.authenticate = function(req, options) {
103 exports = module.exports = AlipayStrategy; 99 exports = module.exports = AlipayStrategy;
104 100
105 exports.Strategy = AlipayStrategy; 101 exports.Strategy = AlipayStrategy;
106 -