index.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. !function (a, b) {
  2. module.exports = b(a)
  3. }(window, function (a, b) {
  4. function c(b, c, d) {
  5. a.WeixinJSBridge ? WeixinJSBridge.invoke(b, e(c), function (a) {
  6. h(b, a, d)
  7. }) : k(b, d)
  8. }
  9. function d(b, c, d) {
  10. a.WeixinJSBridge ? WeixinJSBridge.on(b, function (a) {
  11. d && d.trigger && d.trigger(a), h(b, a, c)
  12. }) : d ? k(b, d) : k(b, c)
  13. }
  14. function e(a) {
  15. return a = a || {}, a.appId = D.appId, a.verifyAppId = D.appId, a.verifySignType = "sha1", a.verifyTimestamp = D.timestamp + "", a.verifyNonceStr = D.nonceStr, a.verifySignature = D.signature, a
  16. }
  17. function f(a) {
  18. return {
  19. timeStamp: a.timestamp + "",
  20. nonceStr: a.nonceStr,
  21. "package": a["package"],
  22. paySign: a.paySign,
  23. signType: a.signType || "SHA1"
  24. }
  25. }
  26. function g(a) {
  27. return a.postalCode = a.addressPostalCode, delete a.addressPostalCode, a.provinceName = a.proviceFirstStageName, delete a.proviceFirstStageName, a.cityName = a.addressCitySecondStageName, delete a.addressCitySecondStageName, a.countryName = a.addressCountiesThirdStageName, delete a.addressCountiesThirdStageName, a.detailInfo = a.addressDetailInfo, delete a.addressDetailInfo, a
  28. }
  29. function h(a, b, c) {
  30. "openEnterpriseChat" == a && (b.errCode = b.err_code), delete b.err_code, delete b.err_desc, delete b.err_detail;
  31. var d = b.errMsg;
  32. d || (d = b.err_msg, delete b.err_msg, d = i(a, d), b.errMsg = d), c = c || {}, c._complete && (c._complete(b), delete c._complete), d = b.errMsg || "", D.debug && !c.isInnerInvoke && alert(JSON.stringify(b));
  33. var e = d.indexOf(":"), f = d.substring(e + 1);
  34. switch (f) {
  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. function i(a, b) {
  47. var c = a, d = q[c];
  48. d && (c = d);
  49. var e = "ok";
  50. if (b) {
  51. var f = b.indexOf(":");
  52. 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")
  53. }
  54. return b = c + ":" + e
  55. }
  56. function j(a) {
  57. if (a) {
  58. for (var b = 0, c = a.length; c > b; ++b) {
  59. var d = a[b], e = p[d];
  60. e && (a[b] = e)
  61. }
  62. return a
  63. }
  64. }
  65. function k(a, b) {
  66. if (!(!D.debug || b && b.isInnerInvoke)) {
  67. var c = q[a];
  68. c && (a = c), b && b._complete && delete b._complete, console.log('"' + a + '",', b || "")
  69. }
  70. }
  71. function l(a) {
  72. if (!(v || w || D.debug || "6.0.2" > A || C.systemType < 0)) {
  73. var b = new Image;
  74. C.appId = D.appId, C.initTime = B.initEndTime - B.initStartTime, C.preVerifyTime = B.preVerifyEndTime - B.preVerifyStartTime, I.getNetworkType({
  75. isInnerInvoke: !0,
  76. success: function (a) {
  77. C.networkType = a.networkType;
  78. var c = "https://open.weixin.qq.com/sdk/report?v=" + C.version + "&o=" + C.isPreVerifyOk + "&s=" + C.systemType + "&c=" + C.clientVersion + "&a=" + C.appId + "&n=" + C.networkType + "&i=" + C.initTime + "&p=" + C.preVerifyTime + "&u=" + C.url;
  79. b.src = c
  80. }
  81. })
  82. }
  83. }
  84. function m() {
  85. return (new Date).getTime()
  86. }
  87. function n(b) {
  88. x && (a.WeixinJSBridge ? b() : r.addEventListener && r.addEventListener("WeixinJSBridgeReady", b, !1))
  89. }
  90. function o() {
  91. I.invoke || (I.invoke = function (b, c, d) {
  92. a.WeixinJSBridge && WeixinJSBridge.invoke(b, e(c), d)
  93. }, I.on = function (b, c) {
  94. a.WeixinJSBridge && WeixinJSBridge.on(b, c)
  95. })
  96. }
  97. if (!a.jWeixin) {
  98. var p = {
  99. config: "preVerifyJSAPI",
  100. onMenuShareTimeline: "menu:share:timeline",
  101. onMenuShareAppMessage: "menu:share:appmessage",
  102. onMenuShareQQ: "menu:share:qq",
  103. onMenuShareWeibo: "menu:share:weiboApp",
  104. onMenuShareQZone: "menu:share:QZone",
  105. previewImage: "imagePreview",
  106. getLocation: "geoLocation",
  107. openProductSpecificView: "openProductViewWithPid",
  108. addCard: "batchAddCard",
  109. openCard: "batchViewCard",
  110. chooseWXPay: "getBrandWCPayRequest",
  111. openEnterpriseRedPacket: "getRecevieBizHongBaoRequest",
  112. startSearchBeacons: "startMonitoringBeacons",
  113. stopSearchBeacons: "stopMonitoringBeacons",
  114. onSearchBeacons: "onBeaconsInRange",
  115. consumeAndShareCard: "consumedShareCard",
  116. openAddress: "editAddress"
  117. }, q = function () {
  118. var a = {};
  119. for (var b in p)a[p[b]] = b;
  120. return a
  121. }(), r = a.document, s = r.title, t = navigator.userAgent.toLowerCase(), u = navigator.platform.toLowerCase(), v = !(!u.match("mac") && !u.match("win")), w = -1 != t.indexOf("wxdebugger"), x = -1 != t.indexOf("micromessenger"), y = -1 != t.indexOf("android"), z = -1 != t.indexOf("iphone") || -1 != t.indexOf("ipad"), A = function () {
  122. var a = t.match(/micromessenger\/(\d+\.\d+\.\d+)/) || t.match(/micromessenger\/(\d+\.\d+)/);
  123. return a ? a[1] : ""
  124. }(), B = {initStartTime: m(), initEndTime: 0, preVerifyStartTime: 0, preVerifyEndTime: 0}, C = {
  125. version: 1,
  126. appId: "",
  127. initTime: 0,
  128. preVerifyTime: 0,
  129. networkType: "",
  130. isPreVerifyOk: 1,
  131. systemType: z ? 1 : y ? 2 : -1,
  132. clientVersion: A,
  133. url: encodeURIComponent(location.href)
  134. }, D = {}, E = {_completes: []}, F = {state: 0, data: {}};
  135. n(function () {
  136. B.initEndTime = m()
  137. });
  138. var G = !1, H = [], I = {
  139. config: function (a) {
  140. D = a, k("config", a);
  141. var b = D.check === !1 ? !1 : !0;
  142. n(function () {
  143. if (b)c(p.config, {verifyJsApiList: j(D.jsApiList)}, function () {
  144. E._complete = function (a) {
  145. B.preVerifyEndTime = m(), F.state = 1, F.data = a
  146. }, E.success = function (a) {
  147. C.isPreVerifyOk = 0
  148. }, E.fail = function (a) {
  149. E._fail ? E._fail(a) : F.state = -1
  150. };
  151. var a = E._completes;
  152. return a.push(function () {
  153. l()
  154. }), E.complete = function (b) {
  155. for (var c = 0, d = a.length; d > c; ++c)a[c]();
  156. E._completes = []
  157. }, E
  158. }()), B.preVerifyStartTime = m(); else {
  159. F.state = 1;
  160. for (var a = E._completes, d = 0, e = a.length; e > d; ++d)a[d]();
  161. E._completes = []
  162. }
  163. }), D.beta && o()
  164. }, ready: function (a) {
  165. 0 != F.state ? a() : (E._completes.push(a), !x && D.debug && a())
  166. }, error: function (a) {
  167. "6.0.2" > A || (-1 == F.state ? a(F.data) : E._fail = a)
  168. }, checkJsApi: function (a) {
  169. var b = function (a) {
  170. var b = a.checkResult;
  171. for (var c in b) {
  172. var d = q[c];
  173. d && (b[d] = b[c], delete b[c])
  174. }
  175. return a
  176. };
  177. c("checkJsApi", {jsApiList: j(a.jsApiList)}, function () {
  178. return a._complete = function (a) {
  179. if (y) {
  180. var c = a.checkResult;
  181. c && (a.checkResult = JSON.parse(c))
  182. }
  183. a = b(a)
  184. }, a
  185. }())
  186. }, onMenuShareTimeline: function (a) {
  187. d(p.onMenuShareTimeline, {
  188. complete: function () {
  189. c("shareTimeline", {
  190. title: a.title || s,
  191. desc: a.title || s,
  192. img_url: a.imgUrl || "",
  193. link: a.link || location.href,
  194. type: a.type || "link",
  195. data_url: a.dataUrl || ""
  196. }, a)
  197. }
  198. }, a)
  199. }, onMenuShareAppMessage: function (a) {
  200. d(p.onMenuShareAppMessage, {
  201. complete: function () {
  202. c("sendAppMessage", {
  203. title: a.title || s,
  204. desc: a.desc || "",
  205. link: a.link || location.href,
  206. img_url: a.imgUrl || "",
  207. type: a.type || "link",
  208. data_url: a.dataUrl || ""
  209. }, a)
  210. }
  211. }, a)
  212. }, onMenuShareQQ: function (a) {
  213. d(p.onMenuShareQQ, {
  214. complete: function () {
  215. c("shareQQ", {
  216. title: a.title || s,
  217. desc: a.desc || "",
  218. img_url: a.imgUrl || "",
  219. link: a.link || location.href
  220. }, a)
  221. }
  222. }, a)
  223. }, onMenuShareWeibo: function (a) {
  224. d(p.onMenuShareWeibo, {
  225. complete: function () {
  226. c("shareWeiboApp", {
  227. title: a.title || s,
  228. desc: a.desc || "",
  229. img_url: a.imgUrl || "",
  230. link: a.link || location.href
  231. }, a)
  232. }
  233. }, a)
  234. }, onMenuShareQZone: function (a) {
  235. d(p.onMenuShareQZone, {
  236. complete: function () {
  237. c("shareQZone", {
  238. title: a.title || s,
  239. desc: a.desc || "",
  240. img_url: a.imgUrl || "",
  241. link: a.link || location.href
  242. }, a)
  243. }
  244. }, a)
  245. }, startRecord: function (a) {
  246. c("startRecord", {}, a)
  247. }, stopRecord: function (a) {
  248. c("stopRecord", {}, a)
  249. }, onVoiceRecordEnd: function (a) {
  250. d("onVoiceRecordEnd", a)
  251. }, playVoice: function (a) {
  252. c("playVoice", {localId: a.localId}, a)
  253. }, pauseVoice: function (a) {
  254. c("pauseVoice", {localId: a.localId}, a)
  255. }, stopVoice: function (a) {
  256. c("stopVoice", {localId: a.localId}, a)
  257. }, onVoicePlayEnd: function (a) {
  258. d("onVoicePlayEnd", a)
  259. }, uploadVoice: function (a) {
  260. c("uploadVoice", {localId: a.localId, isShowProgressTips: 0 == a.isShowProgressTips ? 0 : 1}, a)
  261. }, downloadVoice: function (a) {
  262. c("downloadVoice", {serverId: a.serverId, isShowProgressTips: 0 == a.isShowProgressTips ? 0 : 1}, a)
  263. }, translateVoice: function (a) {
  264. c("translateVoice", {localId: a.localId, isShowProgressTips: 0 == a.isShowProgressTips ? 0 : 1}, a)
  265. }, chooseImage: function (a) {
  266. c("chooseImage", {
  267. scene: "1|2",
  268. count: a.count || 9,
  269. sizeType: a.sizeType || ["original", "compressed"],
  270. sourceType: a.sourceType || ["album", "camera"]
  271. }, function () {
  272. return a._complete = function (a) {
  273. if (y) {
  274. var b = a.localIds;
  275. b && (a.localIds = JSON.parse(b))
  276. }
  277. }, a
  278. }())
  279. }, getLocation: function (a) {
  280. }, previewImage: function (a) {
  281. c(p.previewImage, {current: a.current, urls: a.urls}, a)
  282. }, uploadImage: function (a) {
  283. c("uploadImage", {localId: a.localId, isShowProgressTips: 0 == a.isShowProgressTips ? 0 : 1}, a)
  284. }, downloadImage: function (a) {
  285. c("downloadImage", {serverId: a.serverId, isShowProgressTips: 0 == a.isShowProgressTips ? 0 : 1}, a)
  286. }, getLocalImgData: function (a) {
  287. G === !1 ? (G = !0, c("getLocalImgData", {localId: a.localId}, function () {
  288. return a._complete = function (a) {
  289. if (G = !1, H.length > 0) {
  290. var b = H.shift();
  291. wx.getLocalImgData(b)
  292. }
  293. }, a
  294. }())) : H.push(a)
  295. }, getNetworkType: function (a) {
  296. var b = function (a) {
  297. var b = a.errMsg;
  298. a.errMsg = "getNetworkType:ok";
  299. var c = a.subtype;
  300. if (delete a.subtype, c)a.networkType = c; else {
  301. var d = b.indexOf(":"), e = b.substring(d + 1);
  302. switch (e) {
  303. case"wifi":
  304. case"edge":
  305. case"wwan":
  306. a.networkType = e;
  307. break;
  308. default:
  309. a.errMsg = "getNetworkType:fail"
  310. }
  311. }
  312. return a
  313. };
  314. c("getNetworkType", {}, function () {
  315. return a._complete = function (a) {
  316. a = b(a)
  317. }, a
  318. }())
  319. }, openLocation: function (a) {
  320. c("openLocation", {
  321. latitude: a.latitude,
  322. longitude: a.longitude,
  323. name: a.name || "",
  324. address: a.address || "",
  325. scale: a.scale || 28,
  326. infoUrl: a.infoUrl || ""
  327. }, a)
  328. }, getLocation: function (a) {
  329. a = a || {}, c(p.getLocation, {type: a.type || "wgs84"}, function () {
  330. return a._complete = function (a) {
  331. delete a.type
  332. }, a
  333. }())
  334. }, hideOptionMenu: function (a) {
  335. c("hideOptionMenu", {}, a)
  336. }, showOptionMenu: function (a) {
  337. c("showOptionMenu", {}, a)
  338. }, closeWindow: function (a) {
  339. a = a || {}, c("closeWindow", {}, a)
  340. }, hideMenuItems: function (a) {
  341. c("hideMenuItems", {menuList: a.menuList}, a)
  342. }, showMenuItems: function (a) {
  343. c("showMenuItems", {menuList: a.menuList}, a)
  344. }, hideAllNonBaseMenuItem: function (a) {
  345. c("hideAllNonBaseMenuItem", {}, a)
  346. }, showAllNonBaseMenuItem: function (a) {
  347. c("showAllNonBaseMenuItem", {}, a)
  348. }, scanQRCode: function (a) {
  349. a = a || {}, c("scanQRCode", {
  350. needResult: a.needResult || 0,
  351. scanType: a.scanType || ["qrCode", "barCode"]
  352. }, function () {
  353. return a._complete = function (a) {
  354. if (z) {
  355. var b = a.resultStr;
  356. if (b) {
  357. var c = JSON.parse(b);
  358. a.resultStr = c && c.scan_code && c.scan_code.scan_result
  359. }
  360. }
  361. }, a
  362. }())
  363. }, openAddress: function (a) {
  364. c(p.openAddress, {}, function () {
  365. return a._complete = function (a) {
  366. a = g(a)
  367. }, a
  368. }())
  369. }, openProductSpecificView: function (a) {
  370. c(p.openProductSpecificView, {pid: a.productId, view_type: a.viewType || 0, ext_info: a.extInfo}, a)
  371. }, addCard: function (a) {
  372. for (var b = a.cardList, d = [], e = 0, f = b.length; f > e; ++e) {
  373. var g = b[e], h = {card_id: g.cardId, card_ext: g.cardExt};
  374. d.push(h)
  375. }
  376. c(p.addCard, {card_list: d}, function () {
  377. return a._complete = function (a) {
  378. var b = a.card_list;
  379. if (b) {
  380. b = JSON.parse(b);
  381. for (var c = 0, d = b.length; d > c; ++c) {
  382. var e = b[c];
  383. 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
  384. }
  385. a.cardList = b, delete a.card_list
  386. }
  387. }, a
  388. }())
  389. }, chooseCard: function (a) {
  390. c("chooseCard", {
  391. app_id: D.appId,
  392. location_id: a.shopId || "",
  393. sign_type: a.signType || "SHA1",
  394. card_id: a.cardId || "",
  395. card_type: a.cardType || "",
  396. card_sign: a.cardSign,
  397. time_stamp: a.timestamp + "",
  398. nonce_str: a.nonceStr
  399. }, function () {
  400. return a._complete = function (a) {
  401. a.cardList = a.choose_card_info, delete a.choose_card_info
  402. }, a
  403. }())
  404. }, openCard: function (a) {
  405. for (var b = a.cardList, d = [], e = 0, f = b.length; f > e; ++e) {
  406. var g = b[e], h = {card_id: g.cardId, code: g.code};
  407. d.push(h)
  408. }
  409. c(p.openCard, {card_list: d}, a)
  410. }, consumeAndShareCard: function (a) {
  411. c(p.consumeAndShareCard, {consumedCardId: a.cardId, consumedCode: a.code}, a)
  412. }, chooseWXPay: function (a) {
  413. c(p.chooseWXPay, f(a), a)
  414. }, openEnterpriseRedPacket: function (a) {
  415. c(p.openEnterpriseRedPacket, f(a), a)
  416. }, startSearchBeacons: function (a) {
  417. c(p.startSearchBeacons, {ticket: a.ticket}, a)
  418. }, stopSearchBeacons: function (a) {
  419. c(p.stopSearchBeacons, {}, a)
  420. }, onSearchBeacons: function (a) {
  421. d(p.onSearchBeacons, a)
  422. }, openEnterpriseChat: function (a) {
  423. c("openEnterpriseChat", {useridlist: a.userIds, chatname: a.groupName}, a)
  424. }
  425. }, J = 1, K = {};
  426. return r.addEventListener("error", function (a) {
  427. if (!y) {
  428. var b = a.target, c = b.tagName, d = b.src;
  429. if ("IMG" == c || "VIDEO" == c || "AUDIO" == c || "SOURCE" == c) {
  430. var e = -1 != d.indexOf("wxlocalresource://");
  431. if (e) {
  432. a.preventDefault(), a.stopPropagation();
  433. var f = b["wx-id"];
  434. if (f || (f = J++, b["wx-id"] = f), K[f])return;
  435. K[f] = !0, wx.getLocalImgData({
  436. localId: d, success: function (a) {
  437. b.src = a.localData
  438. }
  439. })
  440. }
  441. }
  442. }
  443. }, !0), r.addEventListener("load", function (a) {
  444. if (!y) {
  445. var b = a.target, c = b.tagName;
  446. b.src;
  447. if ("IMG" == c || "VIDEO" == c || "AUDIO" == c || "SOURCE" == c) {
  448. var d = b["wx-id"];
  449. d && (K[d] = !1)
  450. }
  451. }
  452. }, !0), b && (a.wx = a.jWeixin = I), I
  453. }
  454. });