jweixin.js 16 KB

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