Commit d604327494e3d920d6e45d83647646414d8fef14
1 parent
e483beb0
购好物,对接新版电商API签名校验规则~
Showing
1 changed file
with
51 additions
and
36 deletions
src/main.js
| @@ -156,17 +156,40 @@ Vue.prototype.SIGN = { | @@ -156,17 +156,40 @@ Vue.prototype.SIGN = { | ||
| 156 | 156 | ||
| 157 | /* 根据模式,获取相关请求参数 开始 */ | 157 | /* 根据模式,获取相关请求参数 开始 */ |
| 158 | Vue.prototype.getParams = function(mode) { | 158 | Vue.prototype.getParams = function(mode) { |
| 159 | + | ||
| 160 | + // 随机生成字符串 | ||
| 161 | + function randomString(e) { | ||
| 162 | + e = e || 8; | ||
| 163 | + let t = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678"; | ||
| 164 | + let a = t.length; | ||
| 165 | + let n = ""; | ||
| 166 | + for (let i = 0; i < e; i++) { | ||
| 167 | + n += t.charAt(Math.floor(Math.random() * a)); | ||
| 168 | + } | ||
| 169 | + return n | ||
| 170 | + } | ||
| 171 | + | ||
| 159 | // 返回参数 | 172 | // 返回参数 |
| 160 | let params = {}; | 173 | let params = {}; |
| 161 | 174 | ||
| 175 | + // 请求头 | ||
| 176 | + let app_key = "769_jnjxdh3w53"; | ||
| 177 | + let timestamp = new Date().getTime().toString().substr(0, 10); | ||
| 178 | + let nonce = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCpeLgK0vk5POU5PQ"; | ||
| 179 | + let nonce_str = randomString(8); | ||
| 180 | + | ||
| 162 | switch (mode.toLowerCase()) { | 181 | switch (mode.toLowerCase()) { |
| 163 | case "test": | 182 | case "test": |
| 164 | params.shop = { | 183 | params.shop = { |
| 165 | apiAddress: "https://wjjshop.cnlive.com", | 184 | apiAddress: "https://wjjshop.cnlive.com", |
| 166 | headers: { | 185 | headers: { |
| 167 | - "content-type": "application/x-www-form-urlencoded", | 186 | + "App-Key": app_key, |
| 187 | + "Timestamp": timestamp, | ||
| 188 | + "Signature": sha1(app_key + nonce + nonce_str + timestamp), | ||
| 189 | + "Content-Type": "application/x-www-form-urlencoded", | ||
| 168 | "Phone-Model": "Wap", | 190 | "Phone-Model": "Wap", |
| 169 | - Version: "1.0.1" | 191 | + "Version": "1.0.1", |
| 192 | + "Nonce-Str": nonce_str | ||
| 170 | }, | 193 | }, |
| 171 | sellerCategory: { | 194 | sellerCategory: { |
| 172 | url: "http://wjjh5test.cnlive.com/hqyw.html" | 195 | url: "http://wjjh5test.cnlive.com/hqyw.html" |
| @@ -179,12 +202,8 @@ Vue.prototype.getParams = function(mode) { | @@ -179,12 +202,8 @@ Vue.prototype.getParams = function(mode) { | ||
| 179 | appKey: "9c5619e9be747bb3b925dd215ca5923d86f12c09b9394f", | 202 | appKey: "9c5619e9be747bb3b925dd215ca5923d86f12c09b9394f", |
| 180 | secret: "1e6380cb347255e777f72b5aa60f41daa68443a132aaea", | 203 | secret: "1e6380cb347255e777f72b5aa60f41daa68443a132aaea", |
| 181 | ver: "1.0", | 204 | ver: "1.0", |
| 182 | - page_url: | ||
| 183 | - "https://wjjshop.cnlive.com/html/votes/1/#/pages/redirect/redirect", | ||
| 184 | - timestamp: new Date() | ||
| 185 | - .getTime() | ||
| 186 | - .toString() | ||
| 187 | - .substr(0, 10) | 205 | + // page_url: "https://wjjshop.cnlive.com/html/votes/1/#/pages/redirect/redirect", |
| 206 | + timestamp: new Date().getTime().toString().substr(0, 10) | ||
| 188 | }, | 207 | }, |
| 189 | headers: { | 208 | headers: { |
| 190 | "content-type": "application/x-www-form-urlencoded" | 209 | "content-type": "application/x-www-form-urlencoded" |
| @@ -192,24 +211,16 @@ Vue.prototype.getParams = function(mode) { | @@ -192,24 +211,16 @@ Vue.prototype.getParams = function(mode) { | ||
| 192 | }; | 211 | }; |
| 193 | break; | 212 | break; |
| 194 | case "prod": | 213 | case "prod": |
| 195 | - // 请求头 | ||
| 196 | - let app_key = "769_jnjxdh3w53"; | ||
| 197 | - let timestamp = new Date() | ||
| 198 | - .getTime() | ||
| 199 | - .toString() | ||
| 200 | - .substr(0, 10); | ||
| 201 | - let nonce = | ||
| 202 | - "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCpeLgK0vk5POU5PQ"; | ||
| 203 | - | ||
| 204 | params.shop = { | 214 | params.shop = { |
| 205 | apiAddress: "https://managemall.cnlive.com", | 215 | apiAddress: "https://managemall.cnlive.com", |
| 206 | headers: { | 216 | headers: { |
| 207 | "App-Key": app_key, | 217 | "App-Key": app_key, |
| 208 | - Timestamp: timestamp, | ||
| 209 | - Signature: sha1(app_key + nonce + timestamp), | ||
| 210 | - "content-type": "application/x-www-form-urlencoded", | 218 | + "Timestamp": timestamp, |
| 219 | + "Signature": sha1(app_key + nonce + nonce_str + timestamp), | ||
| 220 | + "Content-Type": "application/x-www-form-urlencoded", | ||
| 211 | "Phone-Model": "Wap", | 221 | "Phone-Model": "Wap", |
| 212 | - Version: "1.0.1" | 222 | + "Version": "1.0.1", |
| 223 | + "Nonce-Str": nonce_str | ||
| 213 | }, | 224 | }, |
| 214 | sellerCategory: { | 225 | sellerCategory: { |
| 215 | url: "http://wjjh5.cnlive.com/hqyw.html" | 226 | url: "http://wjjh5.cnlive.com/hqyw.html" |
| @@ -222,12 +233,8 @@ Vue.prototype.getParams = function(mode) { | @@ -222,12 +233,8 @@ Vue.prototype.getParams = function(mode) { | ||
| 222 | appKey: "0d57b045ec0c3988a682d94c644e66b9b8e0d2b8ef937d", | 233 | appKey: "0d57b045ec0c3988a682d94c644e66b9b8e0d2b8ef937d", |
| 223 | secret: "275e8dc29274a1186d82f65bc607c231d02bcb3bfd8976", | 234 | secret: "275e8dc29274a1186d82f65bc607c231d02bcb3bfd8976", |
| 224 | ver: "1.0", | 235 | ver: "1.0", |
| 225 | - page_url: | ||
| 226 | - "https://managemall.cnlive.com/html/votes/1/#/pages/redirect/redirect", | ||
| 227 | - timestamp: new Date() | ||
| 228 | - .getTime() | ||
| 229 | - .toString() | ||
| 230 | - .substr(0, 10) | 236 | + // page_url: "https://managemall.cnlive.com/html/votes/1/#/pages/redirect/redirect", |
| 237 | + timestamp: new Date().getTime().toString().substr(0, 10) | ||
| 231 | }, | 238 | }, |
| 232 | headers: { | 239 | headers: { |
| 233 | "content-type": "application/x-www-form-urlencoded" | 240 | "content-type": "application/x-www-form-urlencoded" |
| @@ -239,7 +246,13 @@ Vue.prototype.getParams = function(mode) { | @@ -239,7 +246,13 @@ Vue.prototype.getParams = function(mode) { | ||
| 239 | params.shop = { | 246 | params.shop = { |
| 240 | apiAddress: "https://wjjshop.cnlive.com", | 247 | apiAddress: "https://wjjshop.cnlive.com", |
| 241 | headers: { | 248 | headers: { |
| 242 | - "content-type": "application/x-www-form-urlencoded" | 249 | + "App-Key": app_key, |
| 250 | + "Timestamp": timestamp, | ||
| 251 | + "Signature": sha1(app_key + nonce + nonce_str + timestamp), | ||
| 252 | + "Content-Type": "application/x-www-form-urlencoded", | ||
| 253 | + "Phone-Model": "Wap", | ||
| 254 | + "Version": "1.0.1", | ||
| 255 | + "Nonce-Str": nonce_str | ||
| 243 | }, | 256 | }, |
| 244 | sellerCategory: { | 257 | sellerCategory: { |
| 245 | url: "http://wjjh5test.cnlive.com/hqyw.html" | 258 | url: "http://wjjh5test.cnlive.com/hqyw.html" |
| @@ -252,12 +265,8 @@ Vue.prototype.getParams = function(mode) { | @@ -252,12 +265,8 @@ Vue.prototype.getParams = function(mode) { | ||
| 252 | appKey: "9c5619e9be747bb3b925dd215ca5923d86f12c09b9394f", | 265 | appKey: "9c5619e9be747bb3b925dd215ca5923d86f12c09b9394f", |
| 253 | secret: "1e6380cb347255e777f72b5aa60f41daa68443a132aaea", | 266 | secret: "1e6380cb347255e777f72b5aa60f41daa68443a132aaea", |
| 254 | ver: "1.0", | 267 | ver: "1.0", |
| 255 | - page_url: | ||
| 256 | - "http://172.16.2.171:8083/html/votes/1/#/pages/redirect/redirect", | ||
| 257 | - timestamp: new Date() | ||
| 258 | - .getTime() | ||
| 259 | - .toString() | ||
| 260 | - .substr(0, 10) | 268 | + // page_url: "http://172.16.2.171:8083/html/votes/1/#/pages/redirect/redirect", |
| 269 | + timestamp: new Date().getTime().toString().substr(0, 10) | ||
| 261 | }, | 270 | }, |
| 262 | headers: { | 271 | headers: { |
| 263 | "content-type": "application/x-www-form-urlencoded" | 272 | "content-type": "application/x-www-form-urlencoded" |
| @@ -498,6 +507,12 @@ Vue.prototype.http = function(path, data, callback, ext) { | @@ -498,6 +507,12 @@ Vue.prototype.http = function(path, data, callback, ext) { | ||
| 498 | window.location.href = | 507 | window.location.href = |
| 499 | params[api].apiAddress + path + "?" + data.join("&"); | 508 | params[api].apiAddress + path + "?" + data.join("&"); |
| 500 | } else { | 509 | } else { |
| 510 | + | ||
| 511 | + // shop接口,如果请求接口参数有uid,在headers中加入Uid参数 | ||
| 512 | + if (api == 'shop' && data && data.uid) { | ||
| 513 | + params.shop.headers.Uid = data.uid; | ||
| 514 | + } | ||
| 515 | + | ||
| 501 | // 判断请求类型 | 516 | // 判断请求类型 |
| 502 | switch (method) { | 517 | switch (method) { |
| 503 | case "POST": | 518 | case "POST": |
| @@ -508,7 +523,7 @@ Vue.prototype.http = function(path, data, callback, ext) { | @@ -508,7 +523,7 @@ Vue.prototype.http = function(path, data, callback, ext) { | ||
| 508 | data, | 523 | data, |
| 509 | callback, | 524 | callback, |
| 510 | ext, | 525 | ext, |
| 511 | - params.shop.headers | 526 | + params[api].headers |
| 512 | ); | 527 | ); |
| 513 | break; | 528 | break; |
| 514 | case "GET": | 529 | case "GET": |
| @@ -520,7 +535,7 @@ Vue.prototype.http = function(path, data, callback, ext) { | @@ -520,7 +535,7 @@ Vue.prototype.http = function(path, data, callback, ext) { | ||
| 520 | data, | 535 | data, |
| 521 | callback, | 536 | callback, |
| 522 | ext, | 537 | ext, |
| 523 | - params.shop.headers | 538 | + params[api].headers |
| 524 | ); | 539 | ); |
| 525 | break; | 540 | break; |
| 526 | } | 541 | } |