index.js 16 KB

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