jweixin-1.0.0.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. !(function(a, b) {
  2. "function" == typeof define && (define.amd || define.cmd)
  3. ? define(function() {
  4. return b(a);
  5. })
  6. : b(a, !0);
  7. })(this, function(a, b) {
  8. function c(b, c, d) {
  9. a.WeixinJSBridge
  10. ? WeixinJSBridge.invoke(b, e(c), function(a) {
  11. g(b, a, d);
  12. })
  13. : j(b, d);
  14. }
  15. function d(b, c, d) {
  16. a.WeixinJSBridge
  17. ? WeixinJSBridge.on(b, function(a) {
  18. d && d.trigger && d.trigger(a), g(b, a, c);
  19. })
  20. : d ? j(b, d) : j(b, c);
  21. }
  22. function e(a) {
  23. 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;
  24. }
  25. function f(a) {
  26. return {
  27. timeStamp: a.timestamp + "",
  28. nonceStr: a.nonceStr,
  29. package: a.package,
  30. paySign: a.paySign,
  31. signType: a.signType || "SHA1"
  32. };
  33. }
  34. function g(a, b, c) {
  35. var d, e, f;
  36. switch ((delete b.err_code, delete b.err_desc, delete b.err_detail, (d =
  37. 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)))) {
  38. case "ok":
  39. c.success && c.success(b);
  40. break;
  41. case "cancel":
  42. c.cancel && c.cancel(b);
  43. break;
  44. default:
  45. c.fail && c.fail(b);
  46. }
  47. c.complete && c.complete(b);
  48. }
  49. function h(a, b) {
  50. var e, f, c = a, d = p[c];
  51. return d &&
  52. (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);
  53. }
  54. function i(a) {
  55. var b, c, d, e;
  56. if (a) {
  57. for ((b = 0), (c = a.length); c > b; ++b)
  58. (d = a[b]), (e = o[d]), e && (a[b] = e);
  59. return a;
  60. }
  61. }
  62. function j(a, b) {
  63. if (!(!E.debug || (b && b.isInnerInvoke))) {
  64. var c = p[a];
  65. c && (a = c), b && b._complete && delete b._complete, console.log(
  66. '"' + a + '",',
  67. b || ""
  68. );
  69. }
  70. }
  71. function k() {
  72. 0 != D.preVerifyState &&
  73. (u ||
  74. v ||
  75. E.debug ||
  76. "6.0.2" > z ||
  77. D.systemType < 0 ||
  78. A ||
  79. ((A = !0), (D.appId = E.appId), (D.initTime =
  80. C.initEndTime - C.initStartTime), (D.preVerifyTime =
  81. C.preVerifyEndTime - C.preVerifyStartTime), H.getNetworkType({
  82. isInnerInvoke: !0,
  83. success: function(a) {
  84. var b, c;
  85. (D.networkType = a.networkType), (b =
  86. "http://open.weixin.qq.com/sdk/report?v=" +
  87. D.version +
  88. "&o=" +
  89. D.preVerifyState +
  90. "&s=" +
  91. D.systemType +
  92. "&c=" +
  93. D.clientVersion +
  94. "&a=" +
  95. D.appId +
  96. "&n=" +
  97. D.networkType +
  98. "&i=" +
  99. D.initTime +
  100. "&p=" +
  101. D.preVerifyTime +
  102. "&u=" +
  103. D.url), (c = new Image()), (c.src = b);
  104. }
  105. })));
  106. }
  107. function l() {
  108. return new Date().getTime();
  109. }
  110. function m(b) {
  111. w &&
  112. (a.WeixinJSBridge
  113. ? b()
  114. : q.addEventListener &&
  115. q.addEventListener("WeixinJSBridgeReady", b, !1));
  116. }
  117. function n() {
  118. H.invoke ||
  119. ((H.invoke = function(b, c, d) {
  120. a.WeixinJSBridge && WeixinJSBridge.invoke(b, e(c), d);
  121. }), (H.on = function(b, c) {
  122. a.WeixinJSBridge && WeixinJSBridge.on(b, c);
  123. }));
  124. }
  125. var o, p, q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F, G, H;
  126. if (!a.jWeixin)
  127. return (o = {
  128. config: "preVerifyJSAPI",
  129. onMenuShareTimeline: "menu:share:timeline",
  130. onMenuShareAppMessage: "menu:share:appmessage",
  131. onMenuShareQQ: "menu:share:qq",
  132. onMenuShareWeibo: "menu:share:weiboApp",
  133. onMenuShareQZone: "menu:share:QZone",
  134. previewImage: "imagePreview",
  135. getLocation: "geoLocation",
  136. openProductSpecificView: "openProductViewWithPid",
  137. addCard: "batchAddCard",
  138. openCard: "batchViewCard",
  139. chooseWXPay: "getBrandWCPayRequest"
  140. }), (p = (function() {
  141. var b, a = {};
  142. for (b in o)
  143. a[o[b]] = b;
  144. return a;
  145. })()), (q = a.document), (r =
  146. q.title), (s = navigator.userAgent.toLowerCase()), (t = navigator.platform.toLowerCase()), (u = !(!t.match(
  147. "mac"
  148. ) && !t.match("win"))), (v = -1 != s.indexOf("wxdebugger")), (w =
  149. -1 != s.indexOf("micromessenger")), (x = -1 != s.indexOf("android")), (y =
  150. -1 != s.indexOf("iphone") || -1 != s.indexOf("ipad")), (z = (function() {
  151. var a =
  152. s.match(/micromessenger\/(\d+\.\d+\.\d+)/) ||
  153. s.match(/micromessenger\/(\d+\.\d+)/);
  154. return a ? a[1] : "";
  155. })()), (A = !1), (B = !1), (C = {
  156. initStartTime: l(),
  157. initEndTime: 0,
  158. preVerifyStartTime: 0,
  159. preVerifyEndTime: 0
  160. }), (D = {
  161. version: 1,
  162. appId: "",
  163. initTime: 0,
  164. preVerifyTime: 0,
  165. networkType: "",
  166. preVerifyState: 1,
  167. systemType: y ? 1 : x ? 2 : -1,
  168. clientVersion: z,
  169. url: encodeURIComponent(location.href)
  170. }), (E = {}), (F = { _completes: [] }), (G = {
  171. state: 0,
  172. data: {}
  173. }), m(function() {
  174. C.initEndTime = l();
  175. }), (H = {
  176. config: function(a) {
  177. (E = a), j("config", a);
  178. var b = E.check === !1 ? !1 : !0;
  179. m(function() {
  180. var a, d, e;
  181. if (b)
  182. c(
  183. o.config,
  184. { verifyJsApiList: i(E.jsApiList) },
  185. (function() {
  186. (F._complete = function(a) {
  187. (C.preVerifyEndTime = l()), (G.state = 1), (G.data = a);
  188. }), (F.success = function() {
  189. D.preVerifyState = 0;
  190. }), (F.fail = function(a) {
  191. F._fail ? F._fail(a) : (G.state = -1);
  192. });
  193. var a = F._completes;
  194. return a.push(function() {
  195. k();
  196. }), (F.complete = function() {
  197. for (var c = 0, d = a.length; d > c; ++c)
  198. a[c]();
  199. F._completes = [];
  200. }), F;
  201. })()
  202. ), (C.preVerifyStartTime = l());
  203. else {
  204. for (
  205. (G.state = 1), (a = F._completes), (d = 0), (e = a.length);
  206. e > d;
  207. ++d
  208. )
  209. a[d]();
  210. F._completes = [];
  211. }
  212. }), E.beta && n();
  213. },
  214. ready: function(a) {
  215. 0 != G.state ? a() : (F._completes.push(a), !w && E.debug && a());
  216. },
  217. error: function(a) {
  218. "6.0.2" > z ||
  219. B ||
  220. ((B = !0), -1 == G.state ? a(G.data) : (F._fail = a));
  221. },
  222. checkJsApi: function(a) {
  223. var b = function(a) {
  224. var c, d, b = a.checkResult;
  225. for (c in b)
  226. (d = p[c]), d && ((b[d] = b[c]), delete b[c]);
  227. return a;
  228. };
  229. c(
  230. "checkJsApi",
  231. { jsApiList: i(a.jsApiList) },
  232. (function() {
  233. return (a._complete = function(a) {
  234. if (x) {
  235. var c = a.checkResult;
  236. c && (a.checkResult = JSON.parse(c));
  237. }
  238. a = b(a);
  239. }), a;
  240. })()
  241. );
  242. },
  243. onMenuShareTimeline: function(a) {
  244. d(
  245. o.onMenuShareTimeline,
  246. {
  247. complete: function() {
  248. c(
  249. "shareTimeline",
  250. {
  251. title: a.title || r,
  252. desc: a.title || r,
  253. img_url: a.imgUrl || "",
  254. link: a.link || location.href,
  255. type: a.type || "link",
  256. data_url: a.dataUrl || ""
  257. },
  258. a
  259. );
  260. }
  261. },
  262. a
  263. );
  264. },
  265. onMenuShareAppMessage: function(a) {
  266. d(
  267. o.onMenuShareAppMessage,
  268. {
  269. complete: function() {
  270. c(
  271. "sendAppMessage",
  272. {
  273. title: a.title || r,
  274. desc: a.desc || "",
  275. link: a.link || location.href,
  276. img_url: a.imgUrl || "",
  277. type: a.type || "link",
  278. data_url: a.dataUrl || ""
  279. },
  280. a
  281. );
  282. }
  283. },
  284. a
  285. );
  286. },
  287. onMenuShareQQ: function(a) {
  288. d(
  289. o.onMenuShareQQ,
  290. {
  291. complete: function() {
  292. c(
  293. "shareQQ",
  294. {
  295. title: a.title || r,
  296. desc: a.desc || "",
  297. img_url: a.imgUrl || "",
  298. link: a.link || location.href
  299. },
  300. a
  301. );
  302. }
  303. },
  304. a
  305. );
  306. },
  307. onMenuShareWeibo: function(a) {
  308. d(
  309. o.onMenuShareWeibo,
  310. {
  311. complete: function() {
  312. c(
  313. "shareWeiboApp",
  314. {
  315. title: a.title || r,
  316. desc: a.desc || "",
  317. img_url: a.imgUrl || "",
  318. link: a.link || location.href
  319. },
  320. a
  321. );
  322. }
  323. },
  324. a
  325. );
  326. },
  327. onMenuShareQZone: function(a) {
  328. d(
  329. o.onMenuShareQZone,
  330. {
  331. complete: function() {
  332. c(
  333. "shareQZone",
  334. {
  335. title: a.title || r,
  336. desc: a.desc || "",
  337. img_url: a.imgUrl || "",
  338. link: a.link || location.href
  339. },
  340. a
  341. );
  342. }
  343. },
  344. a
  345. );
  346. },
  347. startRecord: function(a) {
  348. c("startRecord", {}, a);
  349. },
  350. stopRecord: function(a) {
  351. c("stopRecord", {}, a);
  352. },
  353. onVoiceRecordEnd: function(a) {
  354. d("onVoiceRecordEnd", a);
  355. },
  356. playVoice: function(a) {
  357. c("playVoice", { localId: a.localId }, a);
  358. },
  359. pauseVoice: function(a) {
  360. c("pauseVoice", { localId: a.localId }, a);
  361. },
  362. stopVoice: function(a) {
  363. c("stopVoice", { localId: a.localId }, a);
  364. },
  365. onVoicePlayEnd: function(a) {
  366. d("onVoicePlayEnd", a);
  367. },
  368. uploadVoice: function(a) {
  369. c(
  370. "uploadVoice",
  371. {
  372. localId: a.localId,
  373. isShowProgressTips: 0 == a.isShowProgressTips ? 0 : 1
  374. },
  375. a
  376. );
  377. },
  378. downloadVoice: function(a) {
  379. c(
  380. "downloadVoice",
  381. {
  382. serverId: a.serverId,
  383. isShowProgressTips: 0 == a.isShowProgressTips ? 0 : 1
  384. },
  385. a
  386. );
  387. },
  388. translateVoice: function(a) {
  389. c(
  390. "translateVoice",
  391. {
  392. localId: a.localId,
  393. isShowProgressTips: 0 == a.isShowProgressTips ? 0 : 1
  394. },
  395. a
  396. );
  397. },
  398. chooseImage: function(a) {
  399. c(
  400. "chooseImage",
  401. {
  402. scene: "1|2",
  403. count: a.count || 9,
  404. sizeType: a.sizeType || ["original", "compressed"],
  405. sourceType: a.sourceType || ["album", "camera"]
  406. },
  407. (function() {
  408. return (a._complete = function(a) {
  409. if (x) {
  410. var b = a.localIds;
  411. b && (a.localIds = JSON.parse(b));
  412. }
  413. }), a;
  414. })()
  415. );
  416. },
  417. previewImage: function(a) {
  418. c(o.previewImage, { current: a.current, urls: a.urls }, a);
  419. },
  420. uploadImage: function(a) {
  421. c(
  422. "uploadImage",
  423. {
  424. localId: a.localId,
  425. isShowProgressTips: 0 == a.isShowProgressTips ? 0 : 1
  426. },
  427. a
  428. );
  429. },
  430. downloadImage: function(a) {
  431. c(
  432. "downloadImage",
  433. {
  434. serverId: a.serverId,
  435. isShowProgressTips: 0 == a.isShowProgressTips ? 0 : 1
  436. },
  437. a
  438. );
  439. },
  440. getNetworkType: function(a) {
  441. var b = function(a) {
  442. var c, d, e, b = a.errMsg;
  443. if (
  444. ((a.errMsg = "getNetworkType:ok"), (c =
  445. a.subtype), delete a.subtype, c)
  446. )
  447. a.networkType = c;
  448. else
  449. switch (((d = b.indexOf(":")), (e = b.substring(d + 1)))) {
  450. case "wifi":
  451. case "edge":
  452. case "wwan":
  453. a.networkType = e;
  454. break;
  455. default:
  456. a.errMsg = "getNetworkType:fail";
  457. }
  458. return a;
  459. };
  460. c(
  461. "getNetworkType",
  462. {},
  463. (function() {
  464. return (a._complete = function(a) {
  465. a = b(a);
  466. }), a;
  467. })()
  468. );
  469. },
  470. openLocation: function(a) {
  471. c(
  472. "openLocation",
  473. {
  474. latitude: a.latitude,
  475. longitude: a.longitude,
  476. name: a.name || "",
  477. address: a.address || "",
  478. scale: a.scale || 28,
  479. infoUrl: a.infoUrl || ""
  480. },
  481. a
  482. );
  483. },
  484. getLocation: function(a) {
  485. (a = a || {}), c(
  486. o.getLocation,
  487. { type: a.type || "wgs84" },
  488. (function() {
  489. return (a._complete = function(a) {
  490. delete a.type;
  491. }), a;
  492. })()
  493. );
  494. },
  495. hideOptionMenu: function(a) {
  496. c("hideOptionMenu", {}, a);
  497. },
  498. showOptionMenu: function(a) {
  499. c("showOptionMenu", {}, a);
  500. },
  501. closeWindow: function(a) {
  502. (a = a || {}), c("closeWindow", {}, a);
  503. },
  504. hideMenuItems: function(a) {
  505. c("hideMenuItems", { menuList: a.menuList }, a);
  506. },
  507. showMenuItems: function(a) {
  508. c("showMenuItems", { menuList: a.menuList }, a);
  509. },
  510. hideAllNonBaseMenuItem: function(a) {
  511. c("hideAllNonBaseMenuItem", {}, a);
  512. },
  513. showAllNonBaseMenuItem: function(a) {
  514. c("showAllNonBaseMenuItem", {}, a);
  515. },
  516. scanQRCode: function(a) {
  517. (a = a || {}), c(
  518. "scanQRCode",
  519. {
  520. needResult: a.needResult || 0,
  521. scanType: a.scanType || ["qrCode", "barCode"]
  522. },
  523. (function() {
  524. return (a._complete = function(a) {
  525. var b, c;
  526. y &&
  527. ((b = a.resultStr), b &&
  528. ((c = JSON.parse(b)), (a.resultStr =
  529. c && c.scan_code && c.scan_code.scan_result)));
  530. }), a;
  531. })()
  532. );
  533. },
  534. openProductSpecificView: function(a) {
  535. c(
  536. o.openProductSpecificView,
  537. { pid: a.productId, view_type: a.viewType || 0, ext_info: a.extInfo },
  538. a
  539. );
  540. },
  541. addCard: function(a) {
  542. var e, f, g, h, b = a.cardList, d = [];
  543. for ((e = 0), (f = b.length); f > e; ++e)
  544. (g = b[e]), (h = { card_id: g.cardId, card_ext: g.cardExt }), d.push(
  545. h
  546. );
  547. c(
  548. o.addCard,
  549. { card_list: d },
  550. (function() {
  551. return (a._complete = function(a) {
  552. var c, d, e, b = a.card_list;
  553. if (b) {
  554. for ((b = JSON.parse(b)), (c = 0), (d = b.length); d > c; ++c)
  555. (e = b[c]), (e.cardId = e.card_id), (e.cardExt =
  556. e.card_ext), (e.isSuccess = e.is_succ
  557. ? !0
  558. : !1), delete e.card_id, delete e.card_ext, delete e.is_succ;
  559. (a.cardList = b), delete a.card_list;
  560. }
  561. }), a;
  562. })()
  563. );
  564. },
  565. chooseCard: function(a) {
  566. c(
  567. "chooseCard",
  568. {
  569. app_id: E.appId,
  570. location_id: a.shopId || "",
  571. sign_type: a.signType || "SHA1",
  572. card_id: a.cardId || "",
  573. card_type: a.cardType || "",
  574. card_sign: a.cardSign,
  575. time_stamp: a.timestamp + "",
  576. nonce_str: a.nonceStr
  577. },
  578. (function() {
  579. return (a._complete = function(a) {
  580. (a.cardList = a.choose_card_info), delete a.choose_card_info;
  581. }), a;
  582. })()
  583. );
  584. },
  585. openCard: function(a) {
  586. var e, f, g, h, b = a.cardList, d = [];
  587. for ((e = 0), (f = b.length); f > e; ++e)
  588. (g = b[e]), (h = { card_id: g.cardId, code: g.code }), d.push(h);
  589. c(o.openCard, { card_list: d }, a);
  590. },
  591. chooseWXPay: function(a) {
  592. c(o.chooseWXPay, f(a), a);
  593. }
  594. }), b && (a.wx = a.jWeixin = H), H;
  595. });