├── .gitignore ├── LICENSE ├── README.md ├── gulpfile.js ├── jsbeautifier.org.js ├── jweixin-1.0.0.beautify.js ├── jweixin-1.0.0.js ├── jweixin-ad021d4c53.js ├── naming_conventions.md └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directory 23 | # Commenting this out is preferred by some people, see 24 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- 25 | node_modules 26 | 27 | # Users Environment Variables 28 | .lock-wscript 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Albert 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # wechat-js-sdk-beautify 2 | 3 | 人肉反编译 http://res.wx.qq.com/open/js/jweixin-1.0.0.js 4 | 5 | # with asserts! 6 | 7 | 微信的错误提示简直 (╯°□°)╯︵ ┻━┻ 8 | 9 | 所以在开发环境请使用 jweixin-1.0.0.beautify.js ┬─┬ ノ(°_°ノ) 10 | 11 | # last keepup 12 | 13 | 2017.FEB.03 14 | 15 | # how to 16 | 17 | 1. 运行 `npm run keepup`,会同步最新的 sdk 文件 18 | 2. 然后执行 `git diff jsbeautifier.org.js`,即可查看这期间微信偷偷摸摸改了些什么 19 | 3. 然后到 `jweixin-1.0.0.beautify.js` 把这些 `diff` 更新进去;如果尚未反编译,则直接覆盖;如果已经反编译,则需人肉升级 20 | 21 | # MIT License 22 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var rename = require('gulp-rename'); 3 | var rev = require('gulp-rev'); 4 | 5 | 6 | gulp.task('rev', function () { 7 | return gulp 8 | .src('jweixin-1.0.0.js') 9 | .pipe(rename('jweixin.js')) 10 | .pipe(rev()) 11 | .pipe(gulp.dest('./')); 12 | }); 13 | 14 | -------------------------------------------------------------------------------- /jsbeautifier.org.js: -------------------------------------------------------------------------------- 1 | ! function(a, b) { 2 | "function" == typeof define && (define.amd || define.cmd) ? define(function() { 3 | return b(a) 4 | }) : b(a, !0) 5 | }(this, function(a, b) { 6 | function c(b, c, d) { 7 | a.WeixinJSBridge ? WeixinJSBridge.invoke(b, e(c), function(a) { 8 | g(b, a, d) 9 | }) : j(b, d) 10 | } 11 | 12 | function d(b, c, d) { 13 | a.WeixinJSBridge ? WeixinJSBridge.on(b, function(a) { 14 | d && d.trigger && d.trigger(a), g(b, a, c) 15 | }) : d ? j(b, d) : j(b, c) 16 | } 17 | 18 | function e(a) { 19 | return a = a || {}, a.appId = E.appId, a.verifyAppId = E.appId, a.verifySignType = "sha1", a.verifyTimestamp = E.timestamp + "", a.verifyNonceStr = E.nonceStr, a.verifySignature = E.signature, a 20 | } 21 | 22 | function f(a) { 23 | return { 24 | timeStamp: a.timestamp + "", 25 | nonceStr: a.nonceStr, 26 | "package": a.package, 27 | paySign: a.paySign, 28 | signType: a.signType || "SHA1" 29 | } 30 | } 31 | 32 | function g(a, b, c) { 33 | var d, e, f; 34 | switch (delete b.err_code, delete b.err_desc, delete b.err_detail, d = b.errMsg, d || (d = b.err_msg, delete b.err_msg, d = h(a, d), b.errMsg = d), c = c || {}, c._complete && (c._complete(b), delete c._complete), d = b.errMsg || "", E.debug && !c.isInnerInvoke && alert(JSON.stringify(b)), e = d.indexOf(":"), f = d.substring(e + 1)) { 35 | case "ok": 36 | c.success && c.success(b); 37 | break; 38 | case "cancel": 39 | c.cancel && c.cancel(b); 40 | break; 41 | default: 42 | c.fail && c.fail(b) 43 | } 44 | c.complete && c.complete(b) 45 | } 46 | 47 | function h(a, b) { 48 | var e, f, c = a, 49 | d = p[c]; 50 | return d && (c = d), e = "ok", b && (f = b.indexOf(":"), e = b.substring(f + 1), "confirm" == e && (e = "ok"), "failed" == e && (e = "fail"), -1 != e.indexOf("failed_") && (e = e.substring(7)), -1 != e.indexOf("fail_") && (e = e.substring(5)), e = e.replace(/_/g, " "), e = e.toLowerCase(), ("access denied" == e || "no permission to execute" == e) && (e = "permission denied"), "config" == c && "function not exist" == e && (e = "ok"), "" == e && (e = "fail")), b = c + ":" + e 51 | } 52 | 53 | function i(a) { 54 | var b, c, d, e; 55 | if (a) { 56 | for (b = 0, c = a.length; c > b; ++b) d = a[b], e = o[d], e && (a[b] = e); 57 | return a 58 | } 59 | } 60 | 61 | function j(a, b) { 62 | if (!(!E.debug || b && b.isInnerInvoke)) { 63 | var c = p[a]; 64 | c && (a = c), b && b._complete && delete b._complete, console.log('"' + a + '",', b || "") 65 | } 66 | } 67 | 68 | function k() { 69 | 0 != D.preVerifyState && (u || v || E.debug || "6.0.2" > z || D.systemType < 0 || A || (A = !0, D.appId = E.appId, D.initTime = C.initEndTime - C.initStartTime, D.preVerifyTime = C.preVerifyEndTime - C.preVerifyStartTime, H.getNetworkType({ 70 | isInnerInvoke: !0, 71 | success: function(a) { 72 | var b, c; 73 | D.networkType = a.networkType, b = "http://open.weixin.qq.com/sdk/report?v=" + D.version + "&o=" + D.preVerifyState + "&s=" + D.systemType + "&c=" + D.clientVersion + "&a=" + D.appId + "&n=" + D.networkType + "&i=" + D.initTime + "&p=" + D.preVerifyTime + "&u=" + D.url, c = new Image, c.src = b 74 | } 75 | }))) 76 | } 77 | 78 | function l() { 79 | return (new Date).getTime() 80 | } 81 | 82 | function m(b) { 83 | w && (a.WeixinJSBridge ? b() : q.addEventListener && q.addEventListener("WeixinJSBridgeReady", b, !1)) 84 | } 85 | 86 | function n() { 87 | H.invoke || (H.invoke = function(b, c, d) { 88 | a.WeixinJSBridge && WeixinJSBridge.invoke(b, e(c), d) 89 | }, H.on = function(b, c) { 90 | a.WeixinJSBridge && WeixinJSBridge.on(b, c) 91 | }) 92 | } 93 | var o, p, q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F, G, H; 94 | if (!a.jWeixin) return o = { 95 | config: "preVerifyJSAPI", 96 | onMenuShareTimeline: "menu:share:timeline", 97 | onMenuShareAppMessage: "menu:share:appmessage", 98 | onMenuShareQQ: "menu:share:qq", 99 | onMenuShareWeibo: "menu:share:weiboApp", 100 | onMenuShareQZone: "menu:share:QZone", 101 | previewImage: "imagePreview", 102 | getLocation: "geoLocation", 103 | openProductSpecificView: "openProductViewWithPid", 104 | addCard: "batchAddCard", 105 | openCard: "batchViewCard", 106 | chooseWXPay: "getBrandWCPayRequest" 107 | }, p = function() { 108 | var b, a = {}; 109 | for (b in o) a[o[b]] = b; 110 | return a 111 | }(), q = a.document, r = q.title, s = navigator.userAgent.toLowerCase(), t = navigator.platform.toLowerCase(), u = !(!t.match("mac") && !t.match("win")), v = -1 != s.indexOf("wxdebugger"), w = -1 != s.indexOf("micromessenger"), x = -1 != s.indexOf("android"), y = -1 != s.indexOf("iphone") || -1 != s.indexOf("ipad"), z = function() { 112 | var a = s.match(/micromessenger\/(\d+\.\d+\.\d+)/) || s.match(/micromessenger\/(\d+\.\d+)/); 113 | return a ? a[1] : "" 114 | }(), A = !1, B = !1, C = { 115 | initStartTime: l(), 116 | initEndTime: 0, 117 | preVerifyStartTime: 0, 118 | preVerifyEndTime: 0 119 | }, D = { 120 | version: 1, 121 | appId: "", 122 | initTime: 0, 123 | preVerifyTime: 0, 124 | networkType: "", 125 | preVerifyState: 1, 126 | systemType: y ? 1 : x ? 2 : -1, 127 | clientVersion: z, 128 | url: encodeURIComponent(location.href) 129 | }, E = {}, F = { 130 | _completes: [] 131 | }, G = { 132 | state: 0, 133 | data: {} 134 | }, m(function() { 135 | C.initEndTime = l() 136 | }), H = { 137 | config: function(a) { 138 | E = a, j("config", a); 139 | var b = E.check === !1 ? !1 : !0; 140 | m(function() { 141 | var a, d, e; 142 | if (b) c(o.config, { 143 | verifyJsApiList: i(E.jsApiList) 144 | }, function() { 145 | F._complete = function(a) { 146 | C.preVerifyEndTime = l(), G.state = 1, G.data = a 147 | }, F.success = function() { 148 | D.preVerifyState = 0 149 | }, F.fail = function(a) { 150 | F._fail ? F._fail(a) : G.state = -1 151 | }; 152 | var a = F._completes; 153 | return a.push(function() { 154 | k() 155 | }), F.complete = function() { 156 | for (var c = 0, d = a.length; d > c; ++c) a[c](); 157 | F._completes = [] 158 | }, F 159 | }()), C.preVerifyStartTime = l(); 160 | else { 161 | for (G.state = 1, a = F._completes, d = 0, e = a.length; e > d; ++d) a[d](); 162 | F._completes = [] 163 | } 164 | }), E.beta && n() 165 | }, 166 | ready: function(a) { 167 | 0 != G.state ? a() : (F._completes.push(a), !w && E.debug && a()) 168 | }, 169 | error: function(a) { 170 | "6.0.2" > z || B || (B = !0, -1 == G.state ? a(G.data) : F._fail = a) 171 | }, 172 | checkJsApi: function(a) { 173 | var b = function(a) { 174 | var c, d, b = a.checkResult; 175 | for (c in b) d = p[c], d && (b[d] = b[c], delete b[c]); 176 | return a 177 | }; 178 | c("checkJsApi", { 179 | jsApiList: i(a.jsApiList) 180 | }, function() { 181 | return a._complete = function(a) { 182 | if (x) { 183 | var c = a.checkResult; 184 | c && (a.checkResult = JSON.parse(c)) 185 | } 186 | a = b(a) 187 | }, a 188 | }()) 189 | }, 190 | onMenuShareTimeline: function(a) { 191 | d(o.onMenuShareTimeline, { 192 | complete: function() { 193 | c("shareTimeline", { 194 | title: a.title || r, 195 | desc: a.title || r, 196 | img_url: a.imgUrl || "", 197 | link: a.link || location.href, 198 | type: a.type || "link", 199 | data_url: a.dataUrl || "" 200 | }, a) 201 | } 202 | }, a) 203 | }, 204 | onMenuShareAppMessage: function(a) { 205 | d(o.onMenuShareAppMessage, { 206 | complete: function() { 207 | c("sendAppMessage", { 208 | title: a.title || r, 209 | desc: a.desc || "", 210 | link: a.link || location.href, 211 | img_url: a.imgUrl || "", 212 | type: a.type || "link", 213 | data_url: a.dataUrl || "" 214 | }, a) 215 | } 216 | }, a) 217 | }, 218 | onMenuShareQQ: function(a) { 219 | d(o.onMenuShareQQ, { 220 | complete: function() { 221 | c("shareQQ", { 222 | title: a.title || r, 223 | desc: a.desc || "", 224 | img_url: a.imgUrl || "", 225 | link: a.link || location.href 226 | }, a) 227 | } 228 | }, a) 229 | }, 230 | onMenuShareWeibo: function(a) { 231 | d(o.onMenuShareWeibo, { 232 | complete: function() { 233 | c("shareWeiboApp", { 234 | title: a.title || r, 235 | desc: a.desc || "", 236 | img_url: a.imgUrl || "", 237 | link: a.link || location.href 238 | }, a) 239 | } 240 | }, a) 241 | }, 242 | onMenuShareQZone: function(a) { 243 | d(o.onMenuShareQZone, { 244 | complete: function() { 245 | c("shareQZone", { 246 | title: a.title || r, 247 | desc: a.desc || "", 248 | img_url: a.imgUrl || "", 249 | link: a.link || location.href 250 | }, a) 251 | } 252 | }, a) 253 | }, 254 | startRecord: function(a) { 255 | c("startRecord", {}, a) 256 | }, 257 | stopRecord: function(a) { 258 | c("stopRecord", {}, a) 259 | }, 260 | onVoiceRecordEnd: function(a) { 261 | d("onVoiceRecordEnd", a) 262 | }, 263 | playVoice: function(a) { 264 | c("playVoice", { 265 | localId: a.localId 266 | }, a) 267 | }, 268 | pauseVoice: function(a) { 269 | c("pauseVoice", { 270 | localId: a.localId 271 | }, a) 272 | }, 273 | stopVoice: function(a) { 274 | c("stopVoice", { 275 | localId: a.localId 276 | }, a) 277 | }, 278 | onVoicePlayEnd: function(a) { 279 | d("onVoicePlayEnd", a) 280 | }, 281 | uploadVoice: function(a) { 282 | c("uploadVoice", { 283 | localId: a.localId, 284 | isShowProgressTips: 0 == a.isShowProgressTips ? 0 : 1 285 | }, a) 286 | }, 287 | downloadVoice: function(a) { 288 | c("downloadVoice", { 289 | serverId: a.serverId, 290 | isShowProgressTips: 0 == a.isShowProgressTips ? 0 : 1 291 | }, a) 292 | }, 293 | translateVoice: function(a) { 294 | c("translateVoice", { 295 | localId: a.localId, 296 | isShowProgressTips: 0 == a.isShowProgressTips ? 0 : 1 297 | }, a) 298 | }, 299 | chooseImage: function(a) { 300 | c("chooseImage", { 301 | scene: "1|2", 302 | count: a.count || 9, 303 | sizeType: a.sizeType || ["original", "compressed"], 304 | sourceType: a.sourceType || ["album", "camera"] 305 | }, function() { 306 | return a._complete = function(a) { 307 | if (x) { 308 | var b = a.localIds; 309 | b && (a.localIds = JSON.parse(b)) 310 | } 311 | }, a 312 | }()) 313 | }, 314 | previewImage: function(a) { 315 | c(o.previewImage, { 316 | current: a.current, 317 | urls: a.urls 318 | }, a) 319 | }, 320 | uploadImage: function(a) { 321 | c("uploadImage", { 322 | localId: a.localId, 323 | isShowProgressTips: 0 == a.isShowProgressTips ? 0 : 1 324 | }, a) 325 | }, 326 | downloadImage: function(a) { 327 | c("downloadImage", { 328 | serverId: a.serverId, 329 | isShowProgressTips: 0 == a.isShowProgressTips ? 0 : 1 330 | }, a) 331 | }, 332 | getNetworkType: function(a) { 333 | var b = function(a) { 334 | var c, d, e, b = a.errMsg; 335 | if (a.errMsg = "getNetworkType:ok", c = a.subtype, delete a.subtype, c) a.networkType = c; 336 | else switch (d = b.indexOf(":"), e = b.substring(d + 1)) { 337 | case "wifi": 338 | case "edge": 339 | case "wwan": 340 | a.networkType = e; 341 | break; 342 | default: 343 | a.errMsg = "getNetworkType:fail" 344 | } 345 | return a 346 | }; 347 | c("getNetworkType", {}, function() { 348 | return a._complete = function(a) { 349 | a = b(a) 350 | }, a 351 | }()) 352 | }, 353 | openLocation: function(a) { 354 | c("openLocation", { 355 | latitude: a.latitude, 356 | longitude: a.longitude, 357 | name: a.name || "", 358 | address: a.address || "", 359 | scale: a.scale || 28, 360 | infoUrl: a.infoUrl || "" 361 | }, a) 362 | }, 363 | getLocation: function(a) { 364 | a = a || {}, c(o.getLocation, { 365 | type: a.type || "wgs84" 366 | }, function() { 367 | return a._complete = function(a) { 368 | delete a.type 369 | }, a 370 | }()) 371 | }, 372 | hideOptionMenu: function(a) { 373 | c("hideOptionMenu", {}, a) 374 | }, 375 | showOptionMenu: function(a) { 376 | c("showOptionMenu", {}, a) 377 | }, 378 | closeWindow: function(a) { 379 | a = a || {}, c("closeWindow", {}, a) 380 | }, 381 | hideMenuItems: function(a) { 382 | c("hideMenuItems", { 383 | menuList: a.menuList 384 | }, a) 385 | }, 386 | showMenuItems: function(a) { 387 | c("showMenuItems", { 388 | menuList: a.menuList 389 | }, a) 390 | }, 391 | hideAllNonBaseMenuItem: function(a) { 392 | c("hideAllNonBaseMenuItem", {}, a) 393 | }, 394 | showAllNonBaseMenuItem: function(a) { 395 | c("showAllNonBaseMenuItem", {}, a) 396 | }, 397 | scanQRCode: function(a) { 398 | a = a || {}, c("scanQRCode", { 399 | needResult: a.needResult || 0, 400 | scanType: a.scanType || ["qrCode", "barCode"] 401 | }, function() { 402 | return a._complete = function(a) { 403 | var b, c; 404 | y && (b = a.resultStr, b && (c = JSON.parse(b), a.resultStr = c && c.scan_code && c.scan_code.scan_result)) 405 | }, a 406 | }()) 407 | }, 408 | openProductSpecificView: function(a) { 409 | c(o.openProductSpecificView, { 410 | pid: a.productId, 411 | view_type: a.viewType || 0, 412 | ext_info: a.extInfo 413 | }, a) 414 | }, 415 | addCard: function(a) { 416 | var e, f, g, h, b = a.cardList, 417 | d = []; 418 | for (e = 0, f = b.length; f > e; ++e) g = b[e], h = { 419 | card_id: g.cardId, 420 | card_ext: g.cardExt 421 | }, d.push(h); 422 | c(o.addCard, { 423 | card_list: d 424 | }, function() { 425 | return a._complete = function(a) { 426 | var c, d, e, b = a.card_list; 427 | if (b) { 428 | for (b = JSON.parse(b), c = 0, d = b.length; d > c; ++c) e = b[c], e.cardId = e.card_id, e.cardExt = e.card_ext, e.isSuccess = e.is_succ ? !0 : !1, delete e.card_id, delete e.card_ext, delete e.is_succ; 429 | a.cardList = b, delete a.card_list 430 | } 431 | }, a 432 | }()) 433 | }, 434 | chooseCard: function(a) { 435 | c("chooseCard", { 436 | app_id: E.appId, 437 | location_id: a.shopId || "", 438 | sign_type: a.signType || "SHA1", 439 | card_id: a.cardId || "", 440 | card_type: a.cardType || "", 441 | card_sign: a.cardSign, 442 | time_stamp: a.timestamp + "", 443 | nonce_str: a.nonceStr 444 | }, function() { 445 | return a._complete = function(a) { 446 | a.cardList = a.choose_card_info, delete a.choose_card_info 447 | }, a 448 | }()) 449 | }, 450 | openCard: function(a) { 451 | var e, f, g, h, b = a.cardList, 452 | d = []; 453 | for (e = 0, f = b.length; f > e; ++e) g = b[e], h = { 454 | card_id: g.cardId, 455 | code: g.code 456 | }, d.push(h); 457 | c(o.openCard, { 458 | card_list: d 459 | }, a) 460 | }, 461 | chooseWXPay: function(a) { 462 | c(o.chooseWXPay, f(a), a) 463 | } 464 | }, b && (a.wx = a.jWeixin = H), H 465 | }); -------------------------------------------------------------------------------- /jweixin-1.0.0.beautify.js: -------------------------------------------------------------------------------- 1 | !function wrap(the_global, initialize) { 2 | if (typeof define === 'function' && (define.amd || define.cmd)) { 3 | define(function () { 4 | return initialize(the_global); 5 | }) 6 | } else { 7 | initialize(the_global, true); 8 | } 9 | }(this, function(a, b) { 10 | // a => the_global 11 | // b => initialize 12 | // ** mapping to `invoke` 13 | function c(api_name, conf, conf_of_callback) { 14 | a.WeixinJSBridge ? WeixinJSBridge.invoke(api_name, e(conf), function(result) { 15 | g(api_name, result, conf_of_callback) 16 | }) : j(api_name, conf_of_callback) 17 | } 18 | 19 | // ** mapping to `on` 20 | function d(api_name, conf_of_callback, fixme_another_conf) { 21 | if (a.WeixinJSBridge) { 22 | WeixinJSBridge.on(api_name, function (result) { 23 | if (fixme_another_conf && fixme_another_conf.trigger) { 24 | fixme_another_conf.trigger(result); 25 | } 26 | g(api_name, result, conf_of_callback); 27 | }); 28 | } else { 29 | if (fixme_another_conf) { 30 | j(api_name, fixme_another_conf); 31 | } else { 32 | j(api_name, conf_of_callback); 33 | } 34 | } 35 | } 36 | 37 | function e(conf) { 38 | conf = conf || {}; 39 | 40 | conf.appId = CONFIG_COPY.appId; 41 | conf.verifyAppId = CONFIG_COPY.appId; 42 | conf.verifySignType = "sha1"; 43 | conf.verifyTimestamp = CONFIG_COPY.timestamp + "", 44 | conf.verifyNonceStr = CONFIG_COPY.nonceStr, 45 | conf.verifySignature = CONFIG_COPY.signature 46 | 47 | return conf; 48 | } 49 | 50 | function f(a) { 51 | return { 52 | timeStamp: a.timestamp + "", 53 | nonceStr: a.nonceStr, 54 | "package": a.package, 55 | paySign: a.paySign, 56 | signType: a.signType || "SHA1" 57 | } 58 | } 59 | 60 | // api_name, result, conf_of_callback 61 | function g(a, bridge_result, c) { 62 | delete bridge_result.err_code; 63 | delete bridge_result.err_desc; 64 | delete bridge_result.err_detail; 65 | 66 | var d = bridge_result.errMsg 67 | if (!d) { 68 | d = bridge_result.err_msg; 69 | delete bridge_result.err_msg; 70 | d = h(a, d); 71 | bridge_result.errMsg = d; 72 | } 73 | 74 | c = c || {}; 75 | if (c._complete) { 76 | c._complete(bridge_result); 77 | delete c._complete; 78 | } 79 | 80 | d = bridge_result.errMsg || ""; 81 | 82 | if (CONFIG_COPY.debug && !c.isInnerInvoke) { 83 | alert(JSON.stringify(bridge_result)); 84 | } 85 | 86 | var e = d.indexOf(":"); 87 | var f = d.substring(e + 1); 88 | 89 | switch (f) { 90 | case "ok": 91 | if (c.success) { 92 | c.success(bridge_result); 93 | } 94 | break; 95 | case "cancel": 96 | if (c.cancel) { 97 | c.cancel(bridge_result); 98 | } 99 | break; 100 | default: 101 | if (c.fail) { 102 | c.fail(bridge_result); 103 | } 104 | } 105 | 106 | if (c.complete) { 107 | c.complete(bridge_result) 108 | } 109 | } 110 | 111 | function h(apiName, errMsg) { 112 | var api = apiName; 113 | 114 | if (apiName in API_NAMES_REVERSE) { 115 | api = API_NAMES_REVERSE[apiName]; 116 | } 117 | 118 | var e = 'ok'; 119 | 120 | if (errMsg) { 121 | e = errMsg.substring(errMsg.indexOf(':') + 1); 122 | 123 | if (e === 'confirm') { 124 | e = 'ok'; 125 | } 126 | 127 | if (e === 'failed') { 128 | e = 'fail'; 129 | } 130 | 131 | if (e.indexOf("failed_") > -1) { 132 | e = e.substring(7); 133 | } 134 | 135 | if (e.indexOf("fail_") > -1) { 136 | e = e.substring(5) 137 | } 138 | 139 | e = e.replace(/_/g, " "); 140 | 141 | e = e.toLowerCase(); 142 | 143 | if (e === 'access denied' || e === 'no permission to execute') { 144 | e = 'permission denied'; 145 | } 146 | 147 | if (api === 'config' && e === 'function not exist') { 148 | e = 'ok'; 149 | } 150 | 151 | if (e === '') { 152 | e = 'fail'; 153 | } 154 | } 155 | 156 | errMsg = api + ':' + e; 157 | 158 | return errMsg; 159 | } 160 | 161 | function i(a) { 162 | var b, c, d, e; 163 | if (a) { 164 | for (b = 0, c = a.length; c > b; ++b) d = a[b], e = API_NAMES[d], e && (a[b] = e); 165 | return a 166 | } 167 | } 168 | 169 | function j(a, b) { 170 | if (!(!CONFIG_COPY.debug || b && b.isInnerInvoke)) { 171 | var c = API_NAMES_REVERSE[a]; 172 | c && (a = c), b && b._complete && delete b._complete, console.log('"' + a + '",', b || "") 173 | } 174 | } 175 | 176 | // ** big data for Tecnet, not for you 177 | function statsReport() { 178 | if (STATS_INFO.preVerifyState) { 179 | if (u || v || E.debug || "6.0.2" > z || STATS_INFO.systemType < 0 || A) { 180 | // pass 181 | } else { 182 | A = true; 183 | STATS_INFO.appId = E.appId; 184 | STATS_INFO.initTime = C.initEndTime - C.initStartTime; 185 | STATS_INFO.preVerifyTime = C.preVerifyEndTime - C.preVerifyStartTime; 186 | H.getNetworkType({ 187 | isInnerInvoke: true, 188 | success: function (a) { 189 | STATS_INFO.networkType = a.networkType; 190 | var src = "http://open.weixin.qq.com/sdk/report?v=" + STATS_INFO.version 191 | + "&o=" + STATS_INFO.preVerifyState 192 | + "&s=" + STATS_INFO.systemType 193 | + "&c=" + STATS_INFO.clientVersion 194 | + "&a=" + STATS_INFO.appId 195 | + "&n=" + STATS_INFO.networkType 196 | + "&i=" + STATS_INFO.initTime 197 | + "&p=" + STATS_INFO.preVerifyTime 198 | + "&u=" + STATS_INFO.url; 199 | var img = new Image; 200 | img.src = src; 201 | } 202 | }); 203 | } 204 | } 205 | } 206 | 207 | function now() { 208 | return (new Date).getTime(); 209 | } 210 | 211 | function m (ready_callback) { 212 | if (IS_MICRO_MESSENGER) { 213 | if (a.WeixinJSBridge) { 214 | ready_callback(); 215 | } else { 216 | if (q.addEventListener) { 217 | q.addEventListener("WeixinJSBridgeReady", ready_callback, false); 218 | } 219 | } 220 | } 221 | } 222 | 223 | // ** backdoor? 224 | function beta() { 225 | if (!H.invoke) { 226 | H.invoke = function(b, c, d) { 227 | a.WeixinJSBridge && WeixinJSBridge.invoke(b, e(c), d); 228 | } 229 | H.on = function(b, c) { 230 | a.WeixinJSBridge && WeixinJSBridge.on(b, c); 231 | } 232 | } 233 | } 234 | 235 | var q, 236 | r, 237 | F, 238 | G, 239 | H; 240 | 241 | if (!a.jWeixin) { 242 | var API_NAMES = { 243 | config: "preVerifyJSAPI", 244 | onMenuShareTimeline: "menu:share:timeline", 245 | onMenuShareAppMessage: "menu:share:appmessage", 246 | onMenuShareQQ: "menu:share:qq", 247 | onMenuShareWeibo: "menu:share:weiboApp", 248 | onMenuShareQZone: "menu:share:QZone", 249 | previewImage: "imagePreview", 250 | getLocation: "geoLocation", 251 | openProductSpecificView: "openProductViewWithPid", 252 | addCard: "batchAddCard", 253 | openCard: "batchViewCard", 254 | chooseWXPay: "getBrandWCPayRequest" 255 | }; 256 | 257 | var API_NAMES_REVERSE = (function() { 258 | var names = {}; 259 | for (var key in API_NAMES) { 260 | names[API_NAMES[key]] = key; 261 | } 262 | return names; 263 | }()); 264 | 265 | q = a.document; 266 | r = q.title; 267 | 268 | var user_agent = navigator.userAgent.toLowerCase(); // => s 269 | var t = navigator.platform.toLowerCase(); // => t 270 | var u = !(!t.match("mac") && !t.match("win")); // => u 271 | var v = -1 != user_agent.indexOf("wxdebugger"); // => v 272 | var IS_MICRO_MESSENGER = -1 != user_agent.indexOf("micromessenger"); // => w 273 | var IS_ANDROID = -1 != user_agent.indexOf("android"); // => x 274 | var IS_IOS = -1 != user_agent.indexOf("iphone") || -1 != user_agent.indexOf("ipad"); // => y 275 | 276 | var client_version = function() { // => z 277 | var a = user_agent.match(/micromessenger\/(\d+\.\d+\.\d+)/) || user_agent.match(/micromessenger\/(\d+\.\d+)/); 278 | return a ? a[1] : "" 279 | }(); 280 | 281 | var A = false; // => A 282 | var B = false; // => B 283 | 284 | C = { 285 | initStartTime: now(), 286 | initEndTime: 0, 287 | preVerifyStartTime: 0, 288 | preVerifyEndTime: 0 289 | }; 290 | 291 | var STATS_INFO = { 292 | version: 1, 293 | appId: "", 294 | initTime: 0, 295 | preVerifyTime: 0, 296 | networkType: "", 297 | preVerifyState: 1, 298 | systemType: IS_IOS ? 1 : IS_ANDROID ? 2 : -1, 299 | clientVersion: client_version, 300 | url: encodeURIComponent(location.href) 301 | }; 302 | 303 | var CONFIG_COPY = {}; 304 | 305 | var F = { 306 | _completes: [] 307 | }; 308 | 309 | G = { 310 | state: 0, 311 | res: {} 312 | }; 313 | 314 | m(function() { 315 | C.initEndTime = now() 316 | }); 317 | 318 | H = { 319 | config: function(ORIG_CONF) { 320 | CONFIG_COPY = ORIG_CONF; 321 | 322 | // asserts { 323 | if (!CONFIG_COPY.appId) { 324 | alert('[assert]: appId is required'); 325 | } 326 | 327 | if (!CONFIG_COPY.timestamp) { 328 | alert('[assert]: timestamp is required'); 329 | } 330 | 331 | if (!CONFIG_COPY.nonceStr) { 332 | alert('[assert]: nonceStr is required'); 333 | } 334 | 335 | if (!CONFIG_COPY.signature) { 336 | alert('[assert]: signature is required'); 337 | } 338 | 339 | if (!CONFIG_COPY.jsApiList || CONFIG_COPY.jsApiList.length === 0) { 340 | alert('[assert]: jsApiList is required'); 341 | } 342 | // } asserts 343 | 344 | j("config", ORIG_CONF); 345 | 346 | var b = true 347 | if (CONFIG_COPY.check === false) { 348 | b = false; 349 | } 350 | 351 | m(function() { 352 | var a, d, e; 353 | if (b) { 354 | c( 355 | API_NAMES.config, 356 | { 357 | verifyJsApiList: i(CONFIG_COPY.jsApiList) 358 | }, 359 | function () { 360 | F._complete = function(res) { 361 | C.preVerifyEndTime = now(); 362 | G.state = 1; 363 | G.res = res; 364 | }; 365 | F.success = function() { 366 | STATS_INFO.preVerifyState = 0; 367 | }; 368 | F.fail = function(err) { 369 | F._fail ? F._fail(err) : G.state = -1 370 | }; 371 | 372 | var a = F._completes; 373 | a.push(function () { 374 | if (!CONFIG_COPY.debug) { 375 | statsReport(); 376 | } 377 | }); 378 | 379 | F.complete = function() { 380 | for (var c = 0, d = a.length; d > c; ++c) a[c](); 381 | F._completes = [] 382 | }; 383 | 384 | return F; 385 | }() 386 | ); 387 | 388 | C.preVerifyStartTime = now(); 389 | } else { 390 | for (G.state = 1, a = F._completes, d = 0, e = a.length; e > d; ++d) a[d](); 391 | F._completes = [] 392 | } 393 | }); 394 | 395 | CONFIG_COPY.beta && beta(); 396 | }, 397 | ready: function (callback) { 398 | if (G.state != 0) { 399 | callback(); 400 | } else { 401 | F._completes.push(callback); 402 | if (!IS_MICRO_MESSENGER && CONFIG_COPY.debug) { 403 | callback(); 404 | } 405 | } 406 | }, 407 | error: function(callback) { 408 | if ("6.0.2" > client_version) { 409 | return; 410 | } else { 411 | if (G.state == -1) { 412 | callback(G.res) 413 | } else { 414 | F._fail = callback; 415 | } 416 | } 417 | }, 418 | checkJsApi: function(a) { 419 | var b = function(a) { 420 | var c, d, b = a.checkResult; 421 | for (c in b) d = API_NAMES_REVERSE[c], d && (b[d] = b[c], delete b[c]); 422 | return a 423 | }; 424 | c("checkJsApi", { 425 | jsApiList: i(a.jsApiList) 426 | }, function() { 427 | return a._complete = function(a) { 428 | if (IS_ANDROID) { 429 | var c = a.checkResult; 430 | c && (a.checkResult = JSON.parse(c)) 431 | } 432 | a = b(a) 433 | }, a 434 | }()) 435 | }, 436 | onMenuShareTimeline: function (call_conf) { 437 | d(API_NAMES.onMenuShareTimeline, { 438 | complete: function() { 439 | c("shareTimeline", { 440 | title: call_conf.title || r, // ** document.title 441 | desc: call_conf.title || r, 442 | img_url: call_conf.imgUrl || "", 443 | link: call_conf.link || location.href 444 | }, call_conf) 445 | } 446 | }, call_conf) 447 | }, 448 | onMenuShareAppMessage: function (call_conf) { 449 | d(API_NAMES.onMenuShareAppMessage, { 450 | complete: function() { 451 | c("sendAppMessage", { 452 | title: call_conf.title || r, 453 | desc: call_conf.desc || "", 454 | link: call_conf.link || location.href, 455 | img_url: call_conf.imgUrl || "", 456 | type: call_conf.type || "link", 457 | data_url: call_conf.dataUrl || "" 458 | }, call_conf) 459 | } 460 | }, call_conf) 461 | }, 462 | onMenuShareQQ: function(call_conf) { 463 | d(API_NAMES.onMenuShareQQ, { 464 | complete: function() { 465 | c("shareQQ", { 466 | title: call_conf.title || r, 467 | desc: call_conf.desc || "", 468 | img_url: call_conf.imgUrl || "", 469 | link: call_conf.link || location.href 470 | }, call_conf) 471 | } 472 | }, call_conf) 473 | }, 474 | onMenuShareWeibo: function(call_conf) { 475 | d(API_NAMES.onMenuShareWeibo, { 476 | complete: function() { 477 | c("shareWeiboApp", { 478 | title: call_conf.title || r, 479 | desc: call_conf.desc || "", 480 | img_url: call_conf.imgUrl || "", 481 | link: call_conf.link || location.href 482 | }, call_conf) 483 | } 484 | }, call_conf) 485 | }, 486 | onMenuShareQZone: function(a) { 487 | d(API_NAMES.onMenuShareQZone, { 488 | complete: function() { 489 | c("shareQZone", { 490 | title: a.title || r, 491 | desc: a.desc || "", 492 | img_url: a.imgUrl || "", 493 | link: a.link || location.href 494 | }, a) 495 | } 496 | }, a) 497 | }, 498 | 499 | startRecord: function(a) { 500 | c("startRecord", {}, a) 501 | }, 502 | stopRecord: function(a) { 503 | c("stopRecord", {}, a) 504 | }, 505 | onVoiceRecordEnd: function(a) { 506 | d("onVoiceRecordEnd", a) 507 | }, 508 | playVoice: function(a) { 509 | c("playVoice", { 510 | localId: a.localId 511 | }, a) 512 | }, 513 | pauseVoice: function(a) { 514 | c("pauseVoice", { 515 | localId: a.localId 516 | }, a) 517 | }, 518 | stopVoice: function(a) { 519 | c("stopVoice", { 520 | localId: a.localId 521 | }, a) 522 | }, 523 | onVoicePlayEnd: function(a) { 524 | d("onVoicePlayEnd", a) 525 | }, 526 | uploadVoice: function(a) { 527 | c("uploadVoice", { 528 | localId: a.localId, 529 | isShowProgressTips: 0 == a.isShowProgressTips ? 0 : 1 530 | }, a) 531 | }, 532 | downloadVoice: function(a) { 533 | c("downloadVoice", { 534 | serverId: a.serverId, 535 | isShowProgressTips: 0 == a.isShowProgressTips ? 0 : 1 536 | }, a) 537 | }, 538 | translateVoice: function(a) { 539 | c("translateVoice", { 540 | localId: a.localId, 541 | isShowProgressTips: 0 == a.isShowProgressTips ? 0 : 1 542 | }, a) 543 | }, 544 | chooseImage: function(a) { 545 | c("chooseImage", { 546 | scene: "1|2", 547 | count: a.count || 9, 548 | sizeType: a.sizeType || ["original", "compressed"], 549 | sourceType: a.sourceType || ["album", "camera"] 550 | }, function() { 551 | return a._complete = function(a) { 552 | if (IS_ANDROID) { 553 | var b = a.localIds; 554 | b && (a.localIds = JSON.parse(b)) 555 | } 556 | }, a 557 | }()) 558 | }, 559 | previewImage: function(a) { 560 | c(API_NAMES.previewImage, { 561 | current: a.current, 562 | urls: a.urls 563 | }, a) 564 | }, 565 | uploadImage: function(a) { 566 | c("uploadImage", { 567 | localId: a.localId, 568 | isShowProgressTips: 0 == a.isShowProgressTips ? 0 : 1 569 | }, a) 570 | }, 571 | downloadImage: function(a) { 572 | c("downloadImage", { 573 | serverId: a.serverId, 574 | isShowProgressTips: 0 == a.isShowProgressTips ? 0 : 1 575 | }, a) 576 | }, 577 | getNetworkType: function(a) { 578 | var b = function(a) { 579 | var c, d, e, b = a.errMsg; 580 | if (a.errMsg = "getNetworkType:ok", c = a.subtype, delete a.subtype, c) a.networkType = c; 581 | else switch (d = b.indexOf(":"), e = b.substring(d + 1)) { 582 | case "wifi": 583 | case "edge": 584 | case "wwan": 585 | a.networkType = e; 586 | break; 587 | default: 588 | a.errMsg = "getNetworkType:fail" 589 | } 590 | return a 591 | }; 592 | c("getNetworkType", {}, function() { 593 | return a._complete = function(a) { 594 | a = b(a) 595 | }, a 596 | }()) 597 | }, 598 | openLocation: function(call_conf) { 599 | c("openLocation", { 600 | latitude: call_conf.latitude, 601 | longitude: call_conf.longitude, 602 | name: call_conf.name || "", 603 | address: call_conf.address || "", 604 | scale: call_conf.scale || 28, 605 | infoUrl: call_conf.infoUrl || "" 606 | }, call_conf) 607 | }, 608 | getLocation: function(call_conf) { 609 | call_conf = call_conf || {}; 610 | c(API_NAMES.getLocation, { 611 | // http://en.wikipedia.org/wiki/World_Geodetic_System#A_new_World_Geodetic_System:_WGS_84 612 | type: call_conf.type || "wgs84" 613 | }, function() { 614 | call_conf._complete = function(a) { 615 | delete a.type 616 | } 617 | return call_conf 618 | }()) 619 | }, 620 | hideOptionMenu: function(a) { 621 | c("hideOptionMenu", {}, a) 622 | }, 623 | showOptionMenu: function(a) { 624 | c("showOptionMenu", {}, a) 625 | }, 626 | closeWindow: function(a) { 627 | a = a || {}, c("closeWindow", { 628 | immediate_close: a.immediateClose || 0 629 | }, a) 630 | }, 631 | hideMenuItems: function(a) { 632 | c("hideMenuItems", { 633 | menuList: a.menuList 634 | }, a) 635 | }, 636 | showMenuItems: function(a) { 637 | c("showMenuItems", { 638 | menuList: a.menuList 639 | }, a) 640 | }, 641 | hideAllNonBaseMenuItem: function(a) { 642 | c("hideAllNonBaseMenuItem", {}, a) 643 | }, 644 | showAllNonBaseMenuItem: function(a) { 645 | c("showAllNonBaseMenuItem", {}, a) 646 | }, 647 | scanQRCode: function(call_conf) { 648 | call_conf = call_conf || {}; 649 | c("scanQRCode", { 650 | needResult: call_conf.needResult || 0, 651 | scanType: call_conf.scanType || ["qrCode", "barCode"] 652 | }, function() { 653 | call_conf._complete = function(a) { 654 | var b, c; 655 | IS_IOS && (b = a.resultStr, b && (c = JSON.parse(b), a.resultStr = c && c.scan_code && c.scan_code.scan_result)) 656 | } 657 | return call_conf 658 | }()) 659 | }, 660 | openProductSpecificView: function(a) { 661 | c(API_NAMES.openProductSpecificView, { 662 | pid: a.productId, 663 | view_type: a.viewType || 0, 664 | ext_info: a.extInfo 665 | }, a) 666 | }, 667 | addCard: function(a) { 668 | var e, f, g, h, b = a.cardList, 669 | d = []; 670 | for (e = 0, f = b.length; f > e; ++e) g = b[e], h = { 671 | card_id: g.cardId, 672 | card_ext: g.cardExt 673 | }, d.push(h); 674 | c(API_NAMES.addCard, { 675 | card_list: d 676 | }, function() { 677 | return a._complete = function(a) { 678 | var c, d, e, b = a.card_list; 679 | if (b) { 680 | for (b = JSON.parse(b), c = 0, d = b.length; d > c; ++c) e = b[c], e.cardId = e.card_id, e.cardExt = e.card_ext, e.isSuccess = e.is_succ ? !0 : !1, delete e.card_id, delete e.card_ext, delete e.is_succ; 681 | a.cardList = b, delete a.card_list 682 | } 683 | }, a 684 | }()) 685 | }, 686 | chooseCard: function(a) { 687 | c("chooseCard", { 688 | app_id: CONFIG_COPY.appId, 689 | location_id: a.shopId || "", 690 | sign_type: a.signType || "SHA1", 691 | card_id: a.cardId || "", 692 | card_type: a.cardType || "", 693 | card_sign: a.cardSign, 694 | time_stamp: a.timestamp + "", 695 | nonce_str: a.nonceStr 696 | }, function() { 697 | return a._complete = function(a) { 698 | a.cardList = a.choose_card_info, delete a.choose_card_info 699 | }, a 700 | }()) 701 | }, 702 | openCard: function(a) { 703 | var e, f, g, h, b = a.cardList, 704 | d = []; 705 | for (e = 0, f = b.length; f > e; ++e) g = b[e], h = { 706 | card_id: g.cardId, 707 | code: g.code 708 | }, d.push(h); 709 | c(API_NAMES.openCard, { 710 | card_list: d 711 | }, a) 712 | }, 713 | chooseWXPay: function(a) { 714 | c(API_NAMES.chooseWXPay, f(a), a) 715 | } 716 | }, b && (a.wx = a.jWeixin = H) 717 | 718 | return H; 719 | } 720 | }); 721 | -------------------------------------------------------------------------------- /jweixin-1.0.0.js: -------------------------------------------------------------------------------- 1 | !function(a,b){"function"==typeof define&&(define.amd||define.cmd)?define(function(){return b(a)}):b(a,!0)}(this,function(a,b){function c(b,c,d){a.WeixinJSBridge?WeixinJSBridge.invoke(b,e(c),function(a){g(b,a,d)}):j(b,d)}function d(b,c,d){a.WeixinJSBridge?WeixinJSBridge.on(b,function(a){d&&d.trigger&&d.trigger(a),g(b,a,c)}):d?j(b,d):j(b,c)}function e(a){return a=a||{},a.appId=E.appId,a.verifyAppId=E.appId,a.verifySignType="sha1",a.verifyTimestamp=E.timestamp+"",a.verifyNonceStr=E.nonceStr,a.verifySignature=E.signature,a}function f(a){return{timeStamp:a.timestamp+"",nonceStr:a.nonceStr,"package":a.package,paySign:a.paySign,signType:a.signType||"SHA1"}}function g(a,b,c){var d,e,f;switch(delete b.err_code,delete b.err_desc,delete b.err_detail,d=b.errMsg,d||(d=b.err_msg,delete b.err_msg,d=h(a,d),b.errMsg=d),c=c||{},c._complete&&(c._complete(b),delete c._complete),d=b.errMsg||"",E.debug&&!c.isInnerInvoke&&alert(JSON.stringify(b)),e=d.indexOf(":"),f=d.substring(e+1)){case"ok":c.success&&c.success(b);break;case"cancel":c.cancel&&c.cancel(b);break;default:c.fail&&c.fail(b)}c.complete&&c.complete(b)}function h(a,b){var e,f,c=a,d=p[c];return d&&(c=d),e="ok",b&&(f=b.indexOf(":"),e=b.substring(f+1),"confirm"==e&&(e="ok"),"failed"==e&&(e="fail"),-1!=e.indexOf("failed_")&&(e=e.substring(7)),-1!=e.indexOf("fail_")&&(e=e.substring(5)),e=e.replace(/_/g," "),e=e.toLowerCase(),("access denied"==e||"no permission to execute"==e)&&(e="permission denied"),"config"==c&&"function not exist"==e&&(e="ok"),""==e&&(e="fail")),b=c+":"+e}function i(a){var b,c,d,e;if(a){for(b=0,c=a.length;c>b;++b)d=a[b],e=o[d],e&&(a[b]=e);return a}}function j(a,b){if(!(!E.debug||b&&b.isInnerInvoke)){var c=p[a];c&&(a=c),b&&b._complete&&delete b._complete,console.log('"'+a+'",',b||"")}}function k(){0!=D.preVerifyState&&(u||v||E.debug||"6.0.2">z||D.systemType<0||A||(A=!0,D.appId=E.appId,D.initTime=C.initEndTime-C.initStartTime,D.preVerifyTime=C.preVerifyEndTime-C.preVerifyStartTime,H.getNetworkType({isInnerInvoke:!0,success:function(a){var b,c;D.networkType=a.networkType,b="http://open.weixin.qq.com/sdk/report?v="+D.version+"&o="+D.preVerifyState+"&s="+D.systemType+"&c="+D.clientVersion+"&a="+D.appId+"&n="+D.networkType+"&i="+D.initTime+"&p="+D.preVerifyTime+"&u="+D.url,c=new Image,c.src=b}})))}function l(){return(new Date).getTime()}function m(b){w&&(a.WeixinJSBridge?b():q.addEventListener&&q.addEventListener("WeixinJSBridgeReady",b,!1))}function n(){H.invoke||(H.invoke=function(b,c,d){a.WeixinJSBridge&&WeixinJSBridge.invoke(b,e(c),d)},H.on=function(b,c){a.WeixinJSBridge&&WeixinJSBridge.on(b,c)})}var o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H;if(!a.jWeixin)return o={config:"preVerifyJSAPI",onMenuShareTimeline:"menu:share:timeline",onMenuShareAppMessage:"menu:share:appmessage",onMenuShareQQ:"menu:share:qq",onMenuShareWeibo:"menu:share:weiboApp",onMenuShareQZone:"menu:share:QZone",previewImage:"imagePreview",getLocation:"geoLocation",openProductSpecificView:"openProductViewWithPid",addCard:"batchAddCard",openCard:"batchViewCard",chooseWXPay:"getBrandWCPayRequest"},p=function(){var b,a={};for(b in o)a[o[b]]=b;return a}(),q=a.document,r=q.title,s=navigator.userAgent.toLowerCase(),t=navigator.platform.toLowerCase(),u=!(!t.match("mac")&&!t.match("win")),v=-1!=s.indexOf("wxdebugger"),w=-1!=s.indexOf("micromessenger"),x=-1!=s.indexOf("android"),y=-1!=s.indexOf("iphone")||-1!=s.indexOf("ipad"),z=function(){var a=s.match(/micromessenger\/(\d+\.\d+\.\d+)/)||s.match(/micromessenger\/(\d+\.\d+)/);return a?a[1]:""}(),A=!1,B=!1,C={initStartTime:l(),initEndTime:0,preVerifyStartTime:0,preVerifyEndTime:0},D={version:1,appId:"",initTime:0,preVerifyTime:0,networkType:"",preVerifyState:1,systemType:y?1:x?2:-1,clientVersion:z,url:encodeURIComponent(location.href)},E={},F={_completes:[]},G={state:0,data:{}},m(function(){C.initEndTime=l()}),H={config:function(a){E=a,j("config",a);var b=E.check===!1?!1:!0;m(function(){var a,d,e;if(b)c(o.config,{verifyJsApiList:i(E.jsApiList)},function(){F._complete=function(a){C.preVerifyEndTime=l(),G.state=1,G.data=a},F.success=function(){D.preVerifyState=0},F.fail=function(a){F._fail?F._fail(a):G.state=-1};var a=F._completes;return a.push(function(){k()}),F.complete=function(){for(var c=0,d=a.length;d>c;++c)a[c]();F._completes=[]},F}()),C.preVerifyStartTime=l();else{for(G.state=1,a=F._completes,d=0,e=a.length;e>d;++d)a[d]();F._completes=[]}}),E.beta&&n()},ready:function(a){0!=G.state?a():(F._completes.push(a),!w&&E.debug&&a())},error:function(a){"6.0.2">z||B||(B=!0,-1==G.state?a(G.data):F._fail=a)},checkJsApi:function(a){var b=function(a){var c,d,b=a.checkResult;for(c in b)d=p[c],d&&(b[d]=b[c],delete b[c]);return a};c("checkJsApi",{jsApiList:i(a.jsApiList)},function(){return a._complete=function(a){if(x){var c=a.checkResult;c&&(a.checkResult=JSON.parse(c))}a=b(a)},a}())},onMenuShareTimeline:function(a){d(o.onMenuShareTimeline,{complete:function(){c("shareTimeline",{title:a.title||r,desc:a.title||r,img_url:a.imgUrl||"",link:a.link||location.href,type:a.type||"link",data_url:a.dataUrl||""},a)}},a)},onMenuShareAppMessage:function(a){d(o.onMenuShareAppMessage,{complete:function(){c("sendAppMessage",{title:a.title||r,desc:a.desc||"",link:a.link||location.href,img_url:a.imgUrl||"",type:a.type||"link",data_url:a.dataUrl||""},a)}},a)},onMenuShareQQ:function(a){d(o.onMenuShareQQ,{complete:function(){c("shareQQ",{title:a.title||r,desc:a.desc||"",img_url:a.imgUrl||"",link:a.link||location.href},a)}},a)},onMenuShareWeibo:function(a){d(o.onMenuShareWeibo,{complete:function(){c("shareWeiboApp",{title:a.title||r,desc:a.desc||"",img_url:a.imgUrl||"",link:a.link||location.href},a)}},a)},onMenuShareQZone:function(a){d(o.onMenuShareQZone,{complete:function(){c("shareQZone",{title:a.title||r,desc:a.desc||"",img_url:a.imgUrl||"",link:a.link||location.href},a)}},a)},startRecord:function(a){c("startRecord",{},a)},stopRecord:function(a){c("stopRecord",{},a)},onVoiceRecordEnd:function(a){d("onVoiceRecordEnd",a)},playVoice:function(a){c("playVoice",{localId:a.localId},a)},pauseVoice:function(a){c("pauseVoice",{localId:a.localId},a)},stopVoice:function(a){c("stopVoice",{localId:a.localId},a)},onVoicePlayEnd:function(a){d("onVoicePlayEnd",a)},uploadVoice:function(a){c("uploadVoice",{localId:a.localId,isShowProgressTips:0==a.isShowProgressTips?0:1},a)},downloadVoice:function(a){c("downloadVoice",{serverId:a.serverId,isShowProgressTips:0==a.isShowProgressTips?0:1},a)},translateVoice:function(a){c("translateVoice",{localId:a.localId,isShowProgressTips:0==a.isShowProgressTips?0:1},a)},chooseImage:function(a){c("chooseImage",{scene:"1|2",count:a.count||9,sizeType:a.sizeType||["original","compressed"],sourceType:a.sourceType||["album","camera"]},function(){return a._complete=function(a){if(x){var b=a.localIds;b&&(a.localIds=JSON.parse(b))}},a}())},previewImage:function(a){c(o.previewImage,{current:a.current,urls:a.urls},a)},uploadImage:function(a){c("uploadImage",{localId:a.localId,isShowProgressTips:0==a.isShowProgressTips?0:1},a)},downloadImage:function(a){c("downloadImage",{serverId:a.serverId,isShowProgressTips:0==a.isShowProgressTips?0:1},a)},getNetworkType:function(a){var b=function(a){var c,d,e,b=a.errMsg;if(a.errMsg="getNetworkType:ok",c=a.subtype,delete a.subtype,c)a.networkType=c;else switch(d=b.indexOf(":"),e=b.substring(d+1)){case"wifi":case"edge":case"wwan":a.networkType=e;break;default:a.errMsg="getNetworkType:fail"}return a};c("getNetworkType",{},function(){return a._complete=function(a){a=b(a)},a}())},openLocation:function(a){c("openLocation",{latitude:a.latitude,longitude:a.longitude,name:a.name||"",address:a.address||"",scale:a.scale||28,infoUrl:a.infoUrl||""},a)},getLocation:function(a){a=a||{},c(o.getLocation,{type:a.type||"wgs84"},function(){return a._complete=function(a){delete a.type},a}())},hideOptionMenu:function(a){c("hideOptionMenu",{},a)},showOptionMenu:function(a){c("showOptionMenu",{},a)},closeWindow:function(a){a=a||{},c("closeWindow",{},a)},hideMenuItems:function(a){c("hideMenuItems",{menuList:a.menuList},a)},showMenuItems:function(a){c("showMenuItems",{menuList:a.menuList},a)},hideAllNonBaseMenuItem:function(a){c("hideAllNonBaseMenuItem",{},a)},showAllNonBaseMenuItem:function(a){c("showAllNonBaseMenuItem",{},a)},scanQRCode:function(a){a=a||{},c("scanQRCode",{needResult:a.needResult||0,scanType:a.scanType||["qrCode","barCode"]},function(){return a._complete=function(a){var b,c;y&&(b=a.resultStr,b&&(c=JSON.parse(b),a.resultStr=c&&c.scan_code&&c.scan_code.scan_result))},a}())},openProductSpecificView:function(a){c(o.openProductSpecificView,{pid:a.productId,view_type:a.viewType||0,ext_info:a.extInfo},a)},addCard:function(a){var e,f,g,h,b=a.cardList,d=[];for(e=0,f=b.length;f>e;++e)g=b[e],h={card_id:g.cardId,card_ext:g.cardExt},d.push(h);c(o.addCard,{card_list:d},function(){return a._complete=function(a){var c,d,e,b=a.card_list;if(b){for(b=JSON.parse(b),c=0,d=b.length;d>c;++c)e=b[c],e.cardId=e.card_id,e.cardExt=e.card_ext,e.isSuccess=e.is_succ?!0:!1,delete e.card_id,delete e.card_ext,delete e.is_succ;a.cardList=b,delete a.card_list}},a}())},chooseCard:function(a){c("chooseCard",{app_id:E.appId,location_id:a.shopId||"",sign_type:a.signType||"SHA1",card_id:a.cardId||"",card_type:a.cardType||"",card_sign:a.cardSign,time_stamp:a.timestamp+"",nonce_str:a.nonceStr},function(){return a._complete=function(a){a.cardList=a.choose_card_info,delete a.choose_card_info},a}())},openCard:function(a){var e,f,g,h,b=a.cardList,d=[];for(e=0,f=b.length;f>e;++e)g=b[e],h={card_id:g.cardId,code:g.code},d.push(h);c(o.openCard,{card_list:d},a)},chooseWXPay:function(a){c(o.chooseWXPay,f(a),a)}},b&&(a.wx=a.jWeixin=H),H}); -------------------------------------------------------------------------------- /jweixin-ad021d4c53.js: -------------------------------------------------------------------------------- 1 | !function(a,b){"function"==typeof define&&(define.amd||define.cmd)?define(function(){return b(a)}):b(a,!0)}(this,function(a,b){function c(b,c,d){a.WeixinJSBridge?WeixinJSBridge.invoke(b,e(c),function(a){g(b,a,d)}):j(b,d)}function d(b,c,d){a.WeixinJSBridge?WeixinJSBridge.on(b,function(a){d&&d.trigger&&d.trigger(a),g(b,a,c)}):d?j(b,d):j(b,c)}function e(a){return a=a||{},a.appId=E.appId,a.verifyAppId=E.appId,a.verifySignType="sha1",a.verifyTimestamp=E.timestamp+"",a.verifyNonceStr=E.nonceStr,a.verifySignature=E.signature,a}function f(a){return{timeStamp:a.timestamp+"",nonceStr:a.nonceStr,"package":a.package,paySign:a.paySign,signType:a.signType||"SHA1"}}function g(a,b,c){var d,e,f;switch(delete b.err_code,delete b.err_desc,delete b.err_detail,d=b.errMsg,d||(d=b.err_msg,delete b.err_msg,d=h(a,d),b.errMsg=d),c=c||{},c._complete&&(c._complete(b),delete c._complete),d=b.errMsg||"",E.debug&&!c.isInnerInvoke&&alert(JSON.stringify(b)),e=d.indexOf(":"),f=d.substring(e+1)){case"ok":c.success&&c.success(b);break;case"cancel":c.cancel&&c.cancel(b);break;default:c.fail&&c.fail(b)}c.complete&&c.complete(b)}function h(a,b){var e,f,c=a,d=p[c];return d&&(c=d),e="ok",b&&(f=b.indexOf(":"),e=b.substring(f+1),"confirm"==e&&(e="ok"),"failed"==e&&(e="fail"),-1!=e.indexOf("failed_")&&(e=e.substring(7)),-1!=e.indexOf("fail_")&&(e=e.substring(5)),e=e.replace(/_/g," "),e=e.toLowerCase(),("access denied"==e||"no permission to execute"==e)&&(e="permission denied"),"config"==c&&"function not exist"==e&&(e="ok"),""==e&&(e="fail")),b=c+":"+e}function i(a){var b,c,d,e;if(a){for(b=0,c=a.length;c>b;++b)d=a[b],e=o[d],e&&(a[b]=e);return a}}function j(a,b){if(!(!E.debug||b&&b.isInnerInvoke)){var c=p[a];c&&(a=c),b&&b._complete&&delete b._complete,console.log('"'+a+'",',b||"")}}function k(){0!=D.preVerifyState&&(u||v||E.debug||"6.0.2">z||D.systemType<0||A||(A=!0,D.appId=E.appId,D.initTime=C.initEndTime-C.initStartTime,D.preVerifyTime=C.preVerifyEndTime-C.preVerifyStartTime,H.getNetworkType({isInnerInvoke:!0,success:function(a){var b,c;D.networkType=a.networkType,b="http://open.weixin.qq.com/sdk/report?v="+D.version+"&o="+D.preVerifyState+"&s="+D.systemType+"&c="+D.clientVersion+"&a="+D.appId+"&n="+D.networkType+"&i="+D.initTime+"&p="+D.preVerifyTime+"&u="+D.url,c=new Image,c.src=b}})))}function l(){return(new Date).getTime()}function m(b){w&&(a.WeixinJSBridge?b():q.addEventListener&&q.addEventListener("WeixinJSBridgeReady",b,!1))}function n(){H.invoke||(H.invoke=function(b,c,d){a.WeixinJSBridge&&WeixinJSBridge.invoke(b,e(c),d)},H.on=function(b,c){a.WeixinJSBridge&&WeixinJSBridge.on(b,c)})}var o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H;if(!a.jWeixin)return o={config:"preVerifyJSAPI",onMenuShareTimeline:"menu:share:timeline",onMenuShareAppMessage:"menu:share:appmessage",onMenuShareQQ:"menu:share:qq",onMenuShareWeibo:"menu:share:weiboApp",onMenuShareQZone:"menu:share:QZone",previewImage:"imagePreview",getLocation:"geoLocation",openProductSpecificView:"openProductViewWithPid",addCard:"batchAddCard",openCard:"batchViewCard",chooseWXPay:"getBrandWCPayRequest"},p=function(){var b,a={};for(b in o)a[o[b]]=b;return a}(),q=a.document,r=q.title,s=navigator.userAgent.toLowerCase(),t=navigator.platform.toLowerCase(),u=!(!t.match("mac")&&!t.match("win")),v=-1!=s.indexOf("wxdebugger"),w=-1!=s.indexOf("micromessenger"),x=-1!=s.indexOf("android"),y=-1!=s.indexOf("iphone")||-1!=s.indexOf("ipad"),z=function(){var a=s.match(/micromessenger\/(\d+\.\d+\.\d+)/)||s.match(/micromessenger\/(\d+\.\d+)/);return a?a[1]:""}(),A=!1,B=!1,C={initStartTime:l(),initEndTime:0,preVerifyStartTime:0,preVerifyEndTime:0},D={version:1,appId:"",initTime:0,preVerifyTime:0,networkType:"",preVerifyState:1,systemType:y?1:x?2:-1,clientVersion:z,url:encodeURIComponent(location.href)},E={},F={_completes:[]},G={state:0,data:{}},m(function(){C.initEndTime=l()}),H={config:function(a){E=a,j("config",a);var b=E.check===!1?!1:!0;m(function(){var a,d,e;if(b)c(o.config,{verifyJsApiList:i(E.jsApiList)},function(){F._complete=function(a){C.preVerifyEndTime=l(),G.state=1,G.data=a},F.success=function(){D.preVerifyState=0},F.fail=function(a){F._fail?F._fail(a):G.state=-1};var a=F._completes;return a.push(function(){k()}),F.complete=function(){for(var c=0,d=a.length;d>c;++c)a[c]();F._completes=[]},F}()),C.preVerifyStartTime=l();else{for(G.state=1,a=F._completes,d=0,e=a.length;e>d;++d)a[d]();F._completes=[]}}),E.beta&&n()},ready:function(a){0!=G.state?a():(F._completes.push(a),!w&&E.debug&&a())},error:function(a){"6.0.2">z||B||(B=!0,-1==G.state?a(G.data):F._fail=a)},checkJsApi:function(a){var b=function(a){var c,d,b=a.checkResult;for(c in b)d=p[c],d&&(b[d]=b[c],delete b[c]);return a};c("checkJsApi",{jsApiList:i(a.jsApiList)},function(){return a._complete=function(a){if(x){var c=a.checkResult;c&&(a.checkResult=JSON.parse(c))}a=b(a)},a}())},onMenuShareTimeline:function(a){d(o.onMenuShareTimeline,{complete:function(){c("shareTimeline",{title:a.title||r,desc:a.title||r,img_url:a.imgUrl||"",link:a.link||location.href,type:a.type||"link",data_url:a.dataUrl||""},a)}},a)},onMenuShareAppMessage:function(a){d(o.onMenuShareAppMessage,{complete:function(){c("sendAppMessage",{title:a.title||r,desc:a.desc||"",link:a.link||location.href,img_url:a.imgUrl||"",type:a.type||"link",data_url:a.dataUrl||""},a)}},a)},onMenuShareQQ:function(a){d(o.onMenuShareQQ,{complete:function(){c("shareQQ",{title:a.title||r,desc:a.desc||"",img_url:a.imgUrl||"",link:a.link||location.href},a)}},a)},onMenuShareWeibo:function(a){d(o.onMenuShareWeibo,{complete:function(){c("shareWeiboApp",{title:a.title||r,desc:a.desc||"",img_url:a.imgUrl||"",link:a.link||location.href},a)}},a)},onMenuShareQZone:function(a){d(o.onMenuShareQZone,{complete:function(){c("shareQZone",{title:a.title||r,desc:a.desc||"",img_url:a.imgUrl||"",link:a.link||location.href},a)}},a)},startRecord:function(a){c("startRecord",{},a)},stopRecord:function(a){c("stopRecord",{},a)},onVoiceRecordEnd:function(a){d("onVoiceRecordEnd",a)},playVoice:function(a){c("playVoice",{localId:a.localId},a)},pauseVoice:function(a){c("pauseVoice",{localId:a.localId},a)},stopVoice:function(a){c("stopVoice",{localId:a.localId},a)},onVoicePlayEnd:function(a){d("onVoicePlayEnd",a)},uploadVoice:function(a){c("uploadVoice",{localId:a.localId,isShowProgressTips:0==a.isShowProgressTips?0:1},a)},downloadVoice:function(a){c("downloadVoice",{serverId:a.serverId,isShowProgressTips:0==a.isShowProgressTips?0:1},a)},translateVoice:function(a){c("translateVoice",{localId:a.localId,isShowProgressTips:0==a.isShowProgressTips?0:1},a)},chooseImage:function(a){c("chooseImage",{scene:"1|2",count:a.count||9,sizeType:a.sizeType||["original","compressed"],sourceType:a.sourceType||["album","camera"]},function(){return a._complete=function(a){if(x){var b=a.localIds;b&&(a.localIds=JSON.parse(b))}},a}())},previewImage:function(a){c(o.previewImage,{current:a.current,urls:a.urls},a)},uploadImage:function(a){c("uploadImage",{localId:a.localId,isShowProgressTips:0==a.isShowProgressTips?0:1},a)},downloadImage:function(a){c("downloadImage",{serverId:a.serverId,isShowProgressTips:0==a.isShowProgressTips?0:1},a)},getNetworkType:function(a){var b=function(a){var c,d,e,b=a.errMsg;if(a.errMsg="getNetworkType:ok",c=a.subtype,delete a.subtype,c)a.networkType=c;else switch(d=b.indexOf(":"),e=b.substring(d+1)){case"wifi":case"edge":case"wwan":a.networkType=e;break;default:a.errMsg="getNetworkType:fail"}return a};c("getNetworkType",{},function(){return a._complete=function(a){a=b(a)},a}())},openLocation:function(a){c("openLocation",{latitude:a.latitude,longitude:a.longitude,name:a.name||"",address:a.address||"",scale:a.scale||28,infoUrl:a.infoUrl||""},a)},getLocation:function(a){a=a||{},c(o.getLocation,{type:a.type||"wgs84"},function(){return a._complete=function(a){delete a.type},a}())},hideOptionMenu:function(a){c("hideOptionMenu",{},a)},showOptionMenu:function(a){c("showOptionMenu",{},a)},closeWindow:function(a){a=a||{},c("closeWindow",{},a)},hideMenuItems:function(a){c("hideMenuItems",{menuList:a.menuList},a)},showMenuItems:function(a){c("showMenuItems",{menuList:a.menuList},a)},hideAllNonBaseMenuItem:function(a){c("hideAllNonBaseMenuItem",{},a)},showAllNonBaseMenuItem:function(a){c("showAllNonBaseMenuItem",{},a)},scanQRCode:function(a){a=a||{},c("scanQRCode",{needResult:a.needResult||0,scanType:a.scanType||["qrCode","barCode"]},function(){return a._complete=function(a){var b,c;y&&(b=a.resultStr,b&&(c=JSON.parse(b),a.resultStr=c&&c.scan_code&&c.scan_code.scan_result))},a}())},openProductSpecificView:function(a){c(o.openProductSpecificView,{pid:a.productId,view_type:a.viewType||0,ext_info:a.extInfo},a)},addCard:function(a){var e,f,g,h,b=a.cardList,d=[];for(e=0,f=b.length;f>e;++e)g=b[e],h={card_id:g.cardId,card_ext:g.cardExt},d.push(h);c(o.addCard,{card_list:d},function(){return a._complete=function(a){var c,d,e,b=a.card_list;if(b){for(b=JSON.parse(b),c=0,d=b.length;d>c;++c)e=b[c],e.cardId=e.card_id,e.cardExt=e.card_ext,e.isSuccess=e.is_succ?!0:!1,delete e.card_id,delete e.card_ext,delete e.is_succ;a.cardList=b,delete a.card_list}},a}())},chooseCard:function(a){c("chooseCard",{app_id:E.appId,location_id:a.shopId||"",sign_type:a.signType||"SHA1",card_id:a.cardId||"",card_type:a.cardType||"",card_sign:a.cardSign,time_stamp:a.timestamp+"",nonce_str:a.nonceStr},function(){return a._complete=function(a){a.cardList=a.choose_card_info,delete a.choose_card_info},a}())},openCard:function(a){var e,f,g,h,b=a.cardList,d=[];for(e=0,f=b.length;f>e;++e)g=b[e],h={card_id:g.cardId,code:g.code},d.push(h);c(o.openCard,{card_list:d},a)},chooseWXPay:function(a){c(o.chooseWXPay,f(a),a)}},b&&(a.wx=a.jWeixin=H),H}); -------------------------------------------------------------------------------- /naming_conventions.md: -------------------------------------------------------------------------------- 1 | Naming Conventions 2 | == 3 | 4 | 1. `call_conf`: when you call the api from some js on some html page 5 | e.g. 6 | var call_conf = { 7 | success: function () { 8 | // blabla 9 | } 10 | }; 11 | wx.getLocation(call_conf); 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wechat-js-sdk-beautify", 3 | "version": "1.0.0", 4 | "description": "人肉反编译 http://res.wx.qq.com/open/js/jweixin-1.0.0.js", 5 | "main": "jweixin-1.0.0.beautify.js", 6 | "scripts": { 7 | "keepup": "rm -f jweixin-1.0.0.js && wget http://res.wx.qq.com/open/js/jweixin-1.0.0.js && js-beautify jweixin-1.0.0.js --outfile jsbeautifier.org.js" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/wechat-developer/wechat-js-sdk-beautify.git" 12 | }, 13 | "author": "hbrls", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/wechat-developer/wechat-js-sdk-beautify/issues" 17 | }, 18 | "homepage": "https://github.com/wechat-developer/wechat-js-sdk-beautify", 19 | "devDependencies": { 20 | "gulp": "3.9.1", 21 | "gulp-rename": "1.2.2", 22 | "gulp-rev": "7.1.2", 23 | "js-beautify": "1.6.8" 24 | } 25 | } 26 | --------------------------------------------------------------------------------