jweixin.js 16 KB

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