entry-igwConfigs.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. import { getStorageDecryptData, setStorageEncryptData } from "@/utils/request";
  2. var wx_code = "",
  3. ticket = "", //票据
  4. accessToken = "",
  5. userInfo = {}, //用户信息
  6. AppInfo = {}, //应用参数
  7. deviceInfo = {}, //设备信息
  8. errorCode = null, //错误码
  9. responseText = "", //错误提示
  10. rootDirLocation = ""; //本地文件路劲
  11. async function onLogin(env) {
  12. //igw相关参数赋值
  13. AppInfo = {
  14. agentid: env.VUE_APP_AGENTID,
  15. corpid: env.VUE_APP_CORPID,
  16. isc_appid: env.VUE_APP_ISCAPPID,
  17. isc_secret: env.VUE_APP_ISCSECRET,
  18. ip: env.VUE_APP_IP,
  19. iscpPort: env.VUE_APP_ISCPPORT,
  20. iscpIP: env.VUE_APP_TSCPIP,
  21. user: env.VUE_APP_USER,
  22. baseUrlIp: env.VUE_APP_BASEURLIP,
  23. baseUrlPort: env.VUE_APP_BASEURLPORT,
  24. appId: env.VUE_APP_APPID,
  25. url_wxcode: env.VUE_APP_URL_WXCODE,
  26. url_ticket: env.VUE_APP_URL_TICKET,
  27. url_accesstoken: env.VUE_APP_URL_ACCESSTOKEN,
  28. url_userinfo: env.VUE_APP_URL_USERINFO,
  29. result: "",
  30. };
  31. return new Promise(async (resolve, reject) => {
  32. try {
  33. //获取设备信息
  34. await getDeviceInfo();
  35. wx_code = await getParam("code");
  36. if (wx_code) {
  37. //获取票据
  38. ticket = await getTicket();
  39. //获取安全交互平台的端口
  40. AppInfo.result = await get_ext_ISCP();
  41. sessionStorage.setItem("IPW_ISCP_PORT", AppInfo.result);
  42. if (env.NODE_ENV == "production") {
  43. //生产环境
  44. //获取密钥信息
  45. var myWords = await getIsolationdmc();
  46. sessionStorage.setItem("YDZY_APP_ISOLATIONDMC", myWords);
  47. //获取isc用户信息
  48. userInfo = await getUser();
  49. } else {
  50. //uat环境
  51. accessToken = await getAccessToken();
  52. userInfo = await getUserinfo();
  53. }
  54. resolve(userInfo);
  55. } else {
  56. //获取wxcode
  57. getWxCode();
  58. }
  59. } catch (error) {
  60. errorCode = error;
  61. reject(errorCode);
  62. }
  63. });
  64. }
  65. async function getParam(variable) {
  66. try {
  67. // isAndroid()
  68. let code = await getAuthCode();
  69. console.log("使用单点登录获取code成功", code)
  70. return code;
  71. } catch (error) {
  72. console.log("单点登录失败,使用URL参数获取", error)
  73. }
  74. let query = window.location.search.substring(1);
  75. let vars = query.split("&");
  76. console.log("单点登录获取code失败,使用微信跳转换取code", vars)
  77. for (let i = 0; i < vars.length; i++) {
  78. var pair = vars[i].split("=");
  79. if (pair[0] == variable) {
  80. return pair[1];
  81. }
  82. }
  83. return "";
  84. }
  85. /**
  86. *
  87. * 获取i国网的code(授权码) 替换之前getWxCode()需要 重定向页面获取wx_code
  88. *
  89. */
  90. function getAuthCode() {
  91. return new Promise((resolve, reject) => {
  92. wx.ready(function () {
  93. wx.invoke(
  94. "getAuthCode",
  95. {
  96. response_type: 'code', //固定值
  97. scope: 'snsapi_base' //固定值
  98. },
  99. function (res) {
  100. console.log("wx_code获取 res:", JSON.stringify(res))
  101. if (res.err_msg === 'getAuthCode:ok') {
  102. wx_code = res.code;
  103. resolve(res.code)
  104. } else {
  105. reject(res)
  106. }
  107. }
  108. );
  109. });
  110. });
  111. }
  112. // 获取密钥信息
  113. function getIsolationdmc() {
  114. // const TyEvent4006 = window.TINGYUN.createAutoEvent({
  115. // key: 'getIsolationdmc-4006'
  116. // })
  117. return new Promise((resolve, reject) => {
  118. $.ajax({
  119. type: "GET",
  120. url: "http://127.0.0.1:" + AppInfo.result + "/test.txt",
  121. success: function (res) {
  122. //更改路径之后接口返回的加密串末尾多了2个空格,导致无法解密,手动去掉
  123. if (res) {
  124. var words = res.split(",");
  125. var myWords = mydecrypt(words[0], words[1].trim());
  126. // TyEvent4006.end();
  127. resolve(myWords);
  128. } else {
  129. responseText = JSON.stringify(res);
  130. // TyEvent4006.fail();
  131. reject(4006);
  132. }
  133. },
  134. error: function (err) {
  135. console.log("生成秘钥失败:", err)
  136. responseText = JSON.stringify(err);
  137. // TyEvent4006.fail();
  138. reject(4006);
  139. },
  140. });
  141. });
  142. }
  143. function isAndroid() {
  144. console.log("是安卓:", navigator.userAgent.indexOf("Android") > -1)
  145. return navigator.userAgent.indexOf("Android") > -1;
  146. }
  147. function getWxCode() {
  148. console.log("code:" + wx_code);
  149. let sURL = AppInfo.url_wxcode;
  150. sURL += "appid=" + AppInfo.corpid;
  151. sURL +=
  152. "&redirect_uri=" + encodeURIComponent("zipapp://local.host/index.html");
  153. sURL += "&response_type=code";
  154. sURL += "&scope=SCOPE";
  155. sURL += "&state=STATE";
  156. sURL += "&agentid=" + AppInfo.agentid;
  157. sURL += "#wechat_redirect";
  158. location.href = sURL;
  159. }
  160. async function getTicket() {
  161. // const TyEvent4001 = window.TINGYUN.createAutoEvent({
  162. // key: 'getTicket-4001'
  163. // })
  164. return new Promise((resolve, reject) => {
  165. var _data = {
  166. appId: AppInfo.agentid,
  167. CODE: wx_code,
  168. };
  169. console.log("获取一次性票据:", _data);
  170. $.ajax({
  171. type: "post",
  172. data: JSON.stringify(_data),
  173. contentType: "application/json;charset=utf-8",
  174. url: AppInfo.url_ticket,
  175. dataType: "json",
  176. async: true,
  177. cache: false,
  178. success: function (res) {
  179. if (res.data && res.data.ticket) {
  180. console.log("获取票据成功:", res);
  181. // TyEvent4001.end();
  182. resolve(res.data.ticket);
  183. } else {
  184. //_data参数异常时,上报的res字符串信息
  185. // TyEvent4001.fail();
  186. console.log("获取一次性票据失败", res);
  187. responseText = JSON.stringify(res);
  188. reject(4001);
  189. }
  190. },
  191. error: function (err) {
  192. console.log("获取一次性票据err", err);
  193. // TyEvent4001.fail();
  194. //err对象里 无其他信息
  195. responseText = '获取一次性票据error';
  196. reject(4001);
  197. },
  198. });
  199. });
  200. }
  201. /** ------------------------分割线 上面步骤为登录,下面步骤为获取用户。根据实际情况选择是否只执行上两步,还是全部流程------------------------**/
  202. // 第三步: 获取接口凭证 accessToken
  203. // accessToken 2个小时内有效,失效前5分钟能获取到新的两个小时有效期token, 为了减少开销 建议保存到本地
  204. //
  205. // 参数说明:(无特殊说明参数可复用)
  206. // appId 是应用创建生成的 isc appid
  207. // clientSecret 是应用创建生成的 isc secret
  208. // 请求头 X-Clientid 是应用创建生成的 isc appid
  209. // 请求头 X-Acloud-Data-Sign 是对请求参数的 sm3 加密串
  210. function getAccessToken() {
  211. return new Promise((resolve) => {
  212. var params = {
  213. appId: AppInfo.isc_appid,
  214. clientSecret: AppInfo.isc_secret,
  215. };
  216. params = JSON.stringify(params);
  217. var DataSign = Sm3Utils.encryptFromText(params);
  218. $.ajax({
  219. url: AppInfo.url_accesstoken,
  220. headers: {
  221. "Content-Type": "application/json;charset=utf8",
  222. Accept: "*/*",
  223. "X-Clientid": AppInfo.isc_appid,
  224. "X-Acloud-Data-Sign": DataSign,
  225. },
  226. type: "POST",
  227. data: params,
  228. success: function (res) {
  229. if (res.code === "100001") {
  230. console.log("accessToken" + res);
  231. resolve(res.data.accessToken);
  232. }
  233. },
  234. error: function (err) {
  235. console.log(err);
  236. },
  237. });
  238. });
  239. }
  240. // 第四步:获取用户信息
  241. // 参数说明:(无特殊说明参数可复用)
  242. // appId 是应用创建生成的 isc appid
  243. // service 是应用创建时编辑的应用主页
  244. // ticket 是第三步返回数据中的 accessToken
  245. // 请求头 X-Acloud-Data-Sign 是对请求参数的 sm3 加密串
  246. // 请求头 X-ISC-AccessToken 中的 AccessToken 是第三步返回数据中的 accessToken
  247. // 注意: 'X-ISC-AccessToken': 'Client ' + AccessToken 的 Client后必须用空格 与 AccessToken隔离
  248. function getUserinfo() {
  249. return new Promise((resolve) => {
  250. var params = {
  251. appId: AppInfo.isc_appid,
  252. service: `zipapp://appid.${AppInfo.agentid}/index.html`,
  253. ticket: ticket,
  254. };
  255. params = JSON.stringify(params);
  256. var DataSign = Sm3Utils.encryptFromText(params);
  257. $.ajax({
  258. url: AppInfo.url_userinfo,
  259. headers: {
  260. "Content-Type": "application/json;charset=utf8",
  261. "X-ISC-AccessToken": "Client " + accessToken,
  262. Accept: "*/*",
  263. "X-Clientid": AppInfo.isc_appid,
  264. "X-Acloud-Data-Sign": DataSign,
  265. },
  266. type: "POST",
  267. data: params,
  268. success: function (res) {
  269. if (res.code === "100001") {
  270. console.log("userinfo" + res);
  271. // ! need delete
  272. sessionStorage.setItem(
  273. "IPW_ISC_ACCOUNTINFO",
  274. JSON.stringify(res.data)
  275. );
  276. setStorageEncryptData("IPW_ISC_ACCOUNTINFO_SECRET", res.data);
  277. resolve({
  278. userId: res.data.userId,
  279. account: res.data.account,
  280. });
  281. }
  282. },
  283. });
  284. });
  285. }
  286. /** get_ext_ISCP 获取安全交互平台返回信息 */
  287. function get_ext_ISCP() {
  288. console.log("ext_ISCP_Init: iscpIP ---:" + AppInfo.iscpIP);
  289. // const TyEvent4003 = window.TINGYUN.createAutoEvent({
  290. // key: 'get-ext-ISCP-4003'
  291. // })
  292. // const TyEvent4004 = window.TINGYUN.createAutoEvent({
  293. // key: 'ext-ISCP-GetLocalPort-4004'
  294. // })
  295. // const TyEvent4005 = window.TINGYUN.createAutoEvent({
  296. // key: 'ext-ISCP-GetLocalPort-4005'
  297. // })
  298. return new Promise((resolve, reject) => {
  299. // wx.ready(function () {
  300. // console.log('准备:wx.config: ready');
  301. // wx.invoke(
  302. // 'agentConfig',
  303. // {
  304. // agentid: AppInfo.agentid, // 必填,企业应用的agentid
  305. // corpid: AppInfo.corpid, // 必填,企业微信的corpid
  306. // timestamp: new Date().valueOf() / 1000, // 必填,生成签名的时间戳,int类型, 如
  307. // nonceStr: '', // 必填,生成签名的随机串
  308. // signature: '' // 必填,签名,见附录5
  309. // },
  310. // function (res) {
  311. // console.log('agentConfig:', res);
  312. // if (res.err_msg != 'agentConfig:ok') {
  313. // reject(4002)
  314. // }
  315. console.log("ext_ISCP_Init 初始化参数iscpIP:", AppInfo.iscpIP);
  316. wx.invoke(
  317. "ext_ISCP_Init",
  318. {
  319. // 初始化交互安全平台
  320. data: {
  321. iscpIP: AppInfo.iscpIP,
  322. },
  323. },
  324. function (res) {
  325. console.log("ext_ISCP_Init 初始化返回:", res);
  326. if (res.err_msg === "ext_ISCP_Init:ok") {
  327. // TyEvent4003.end();
  328. var para = {
  329. ip: AppInfo.ip, //安全交互平台互联网ip,从对接方获取
  330. port: AppInfo.iscpPort, //安全交互平台互联网port,从对接方获取
  331. user: AppInfo.user, //当前登录用户id,可写死
  332. appid: AppInfo.appId, //需要向安全交互平台申请
  333. iscpIP: AppInfo.iscpIP, //链路唯一标识,自己生成(建议赋值为AgentID)
  334. };
  335. console.log("ext_ISCP_ConnectService 建立链接参数: ", para);
  336. wx.invoke(
  337. "ext_ISCP_ConnectService",
  338. {
  339. // 建立安全交互平台链接
  340. data: para,
  341. },
  342. function (res) {
  343. console.log("ext_ISCP_ConnectService 建立链接返回:", res);
  344. if (res.err_msg === "ext_ISCP_ConnectService:ok") {
  345. let _data = {
  346. ip: AppInfo.baseUrlIp,
  347. port: AppInfo.baseUrlPort,
  348. iscpIP: AppInfo.iscpIP,
  349. appid: AppInfo.appId,
  350. };
  351. // TyEvent4004.end();
  352. console.log("ext_ISCP_GetLocalPort 转换端口参数:", _data);
  353. wx.invoke(
  354. "ext_ISCP_GetLocalPort",
  355. {
  356. // 转换端口
  357. data: _data,
  358. },
  359. function (res) {
  360. console.log("ext_ISCP_GetLocalPort 转换端口返回:", res);
  361. if (res.err_msg === "ext_ISCP_GetLocalPort:ok") {
  362. AppInfo.result = res.result;
  363. // TyEvent4005.end();
  364. resolve(res.result);
  365. console.log("**getZipAppDirectory");
  366. wx.invoke(
  367. "getZipAppDirectory",
  368. {
  369. type: "APP_ROOT_DIR",
  370. },
  371. function (res) {
  372. console.log("getZipAppDirectory end", res);
  373. if (res.err_msg === "getZipAppDirectory:ok") {
  374. rootDirLocation = res.directory;
  375. sessionStorage.setItem(
  376. "ROOT_DIR_LOCATION",
  377. res.directory
  378. );
  379. } else {
  380. console.log("getZipAppDirectory end 获取本地路径失败:", res)
  381. }
  382. }
  383. );
  384. } else {
  385. // TyEvent4005.fail();
  386. responseText = JSON.stringify(res);
  387. // responseText = `err_msg:${res.err_msg} - result:${res.result} - exception:${res.exception}`
  388. reject(4005);
  389. }
  390. }
  391. );
  392. } else {
  393. // TyEvent4004.fail();
  394. responseText = JSON.stringify(res);
  395. // responseText = `err_msg:${res.err_msg} - result:${res.result} - UUID:${res.UUID}`
  396. reject(4004);
  397. }
  398. }
  399. );
  400. } else {
  401. // TyEvent4003.fail();
  402. responseText = JSON.stringify(res);
  403. reject(4003);
  404. }
  405. }
  406. );
  407. // }
  408. // );
  409. // window.uexOnload && window.uexOnload(0);
  410. // });
  411. // wx.config({
  412. // beta: true, // 调用wx.invoke形式的接口值时,该值必须为true。
  413. // debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  414. // appId: AppInfo.corpid, // 必填,政务微信的cropID
  415. // timestamp: '1608692903', // 必填,生成签名的时间戳
  416. // nonceStr: 'XKIvykvwOuAeIbl', // 必填,生成签名的随机串
  417. // signature: 'ad0c077e6b5fbfe0c9e5394703d8262a3bc21fc3', // 必填,签名,见附录1
  418. // jsApiList: [
  419. // 'multiWindows_open',
  420. // 'multiWindows_close',
  421. // 'multiWindows_subscribe',
  422. // 'multiWindows_publish',
  423. // 'multiWindows_finish',
  424. // 'chooseImage',
  425. // 'scanQRCode',
  426. // 'hideOptionMenu',
  427. // 'shareWechatMessage',
  428. // 'shareAppMessage',
  429. // 'startAutoLBS',
  430. // 'stopAutoLBS',
  431. // 'onLocationChange',
  432. // 'onMenuShareAppMessage',
  433. // 'onMenuShareWechat',
  434. // 'previewFile',
  435. // 'openChatWithMsg',
  436. // 'ext_Database_Open',
  437. // 'ext_Database_Exec',
  438. // 'ext_Database_Query',
  439. // 'ext_Database_Close',
  440. // 'ext_ISCP_Init',
  441. // 'ext_ISCP_ConnectService',
  442. // 'ext_ISCP_GetLocalPort',
  443. // 'ext_ISCP_Close',
  444. // 'ext_ISCP_Status',
  445. // 'ext_screenControl_direction',
  446. // 'getLocation',
  447. // "getZipAppDirectory",
  448. // "multiWindows_open",
  449. // "ext_DeviceInfo_GetInfo",
  450. // "ext_DeviceInfo_version"
  451. // ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  452. // });
  453. });
  454. }
  455. //通过安全交互平台认证之后调后端接口获取用户信息
  456. // function getUser() {
  457. // if (!AppInfo.result) {
  458. // alert('请先获取交互平台信息');
  459. // return;
  460. // }
  461. // var url = 'http://127.0.0.1:' + AppInfo.result + '/yjapp/service/indexToDefect';
  462. // return new Promise((resolve) => {
  463. // var params = {
  464. // index: 5,
  465. // formData: JSON.stringify({
  466. // serviceTicket: ticket
  467. // }),
  468. // requestURL: '/',
  469. // requestMethod: 'GET'
  470. // };
  471. // $.ajax({
  472. // type: 'post',
  473. // url: url,
  474. // data: params,
  475. // success: function (response) {
  476. // console.log('Got USER', response.data.userId);
  477. // console.log('Got USER', response.data.account);
  478. // resolve({
  479. // userId: response.data.userId,
  480. // account: response.data.account
  481. // });
  482. // },
  483. // error: function (response) {
  484. // fail();
  485. // console.log('fail:' + response);
  486. // console.error(response);
  487. // }
  488. // });
  489. // });
  490. // }
  491. //通过安全交互平台认证之后调后端接口获取用户信息
  492. function getUser() {
  493. if (!AppInfo.result) {
  494. alert("请先获取交互平台信息");
  495. return;
  496. }
  497. // const TyEvent4007 = window.TINGYUN.createAutoEvent({
  498. // key: 'getUser-4007'
  499. // })
  500. // const TyEvenGetUserOther = window.TINGYUN.createAutoEvent({
  501. // key: 'getUser-other'
  502. // })
  503. var url = "http://127.0.0.1:" + AppInfo.result + "/igw-isc/isc/ipw";
  504. return new Promise((resolve, reject) => {
  505. var params = {
  506. serviceTicket: ticket,
  507. };
  508. $.ajax({
  509. type: "post",
  510. url: url,
  511. data: JSON.stringify(params),
  512. contentType: "application/json",
  513. dataType: "json",
  514. success: function (response) {
  515. //token
  516. sessionStorage.setItem(
  517. "IPW_UC_TOKEN",
  518. response.data.ipwToken.resultValue.value
  519. );
  520. // ! need delete
  521. //isc用户信息
  522. sessionStorage.setItem(
  523. "IPW_ISC_ACCOUNTINFO",
  524. JSON.stringify(response.data.iscInfo)
  525. );
  526. setStorageEncryptData("IPW_ISC_ACCOUNTINFO_SECRET", response.data.iscInfo);
  527. // TyEvent4007.end();
  528. // TyEvenGetUserOther.end();
  529. resolve({
  530. userId: response.data.iscInfo.userId,
  531. account: response.data.iscInfo.account,
  532. });
  533. },
  534. error: function (response) {
  535. console.log("===============getUser response", response)
  536. let tempCode;
  537. if (response.responseJSON && response.responseJSON.code) {
  538. if (response.responseJSON.code === -1) {
  539. tempCode = 1001;
  540. response.responseText = "serviceTicket参数不能为空"
  541. } else {
  542. //3002 应该是response.responseJSON.code赋予的
  543. tempCode = response.responseJSON.code;
  544. }
  545. // TyEvenGetUserOther.fail();
  546. } else {
  547. // TyEvent4007.fail();
  548. tempCode = 4007;
  549. //4007的响应体 特殊处理
  550. responseText = JSON.stringify(response);
  551. reject(tempCode);
  552. }
  553. responseText = response.responseText
  554. ? response.responseText
  555. : response.status
  556. ? response.status
  557. : "";
  558. reject(tempCode);
  559. },
  560. });
  561. });
  562. }
  563. //获取设备信息接口
  564. // 参数
  565. // 属性 类型 说明
  566. // err_msg String 方法是否成功依据
  567. // deviceUUID String 设备IMEI(获得不到则返回UUID)
  568. // deviceOS String 操作系统
  569. // deviceManufacturers String 厂商信息
  570. // deviceType String 设备机型
  571. // devicePlatform String 平台类型
  572. // isPhone String 设备种类
  573. // macAddress String 获取mac地址
  574. // lang String 获取系统语言
  575. function getDeviceInfo() {
  576. // const TyEvent4002 = window.TINGYUN.createAutoEvent({
  577. // key: 'getDevice-4002'
  578. // })
  579. return new Promise((resolve, reject) => {
  580. wx.ready(function () {
  581. console.log("准备:wx.config: ready");
  582. wx.invoke(
  583. "agentConfig",
  584. {
  585. agentid: AppInfo.agentid, // 必填,企业应用的agentid
  586. corpid: AppInfo.corpid, // 必填,企业微信的corpid
  587. timestamp: new Date().valueOf() / 1000, // 必填,生成签名的时间戳,int类型, 如
  588. nonceStr: "", // 必填,生成签名的随机串
  589. signature: "", // 必填,签名,见附录5
  590. },
  591. function (res) {
  592. console.log("agentConfig:", res);
  593. if (res.err_msg != "agentConfig:ok") {
  594. // TyEvent4002.fail();
  595. responseText = res.err_msg || "";
  596. reject(4002);
  597. }
  598. // TyEvent4002.end();
  599. // const TyEventGetDeviceInfo = window.TINGYUN.createAutoEvent({
  600. // key: 'Wx-TyEventGetDeviceInfo'
  601. // })
  602. wx.invoke("ext_DeviceInfo_GetInfo", { data: {} }, function (res) {
  603. console.log("获取设备信息--" + JSON.stringify(res));
  604. console.log("获取设备信息result--" + res.result);
  605. if (res.err_msg === "ext_DeviceInfo_GetInfo:ok") {
  606. //成功处理
  607. deviceInfo = { ...res };
  608. // //探针接口方式设置设备ID
  609. // window.TINGYUN && window.TINGYUN.setDid(deviceInfo.deviceUUID || 'xxx');
  610. // //探针接口方式设置用户ID
  611. // window.TINGYUN && window.TINGYUN.setUid(deviceInfo.macAddress || 'xxx.xxx');
  612. // TyEventGetDeviceInfo.end();
  613. console.log("deviceInfo--" + JSON.stringify(deviceInfo));
  614. resolve();
  615. }
  616. if (res.err_msg === "ext_DeviceInfo_GetInfo:fail") {
  617. // TyEventGetDeviceInfo.fail();
  618. //失败处理
  619. resolve();
  620. }
  621. if (res.err_msg === "ext_DeviceInfo_GetInfo:cancel") {
  622. // TyEventGetDeviceInfo.fail();
  623. //取消处理
  624. resolve();
  625. }
  626. });
  627. }
  628. );
  629. window.uexOnload && window.uexOnload(0);
  630. });
  631. wx.config({
  632. beta: true, // 调用wx.invoke形式的接口值时,该值必须为true。
  633. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  634. appId: AppInfo.corpid, // 必填,政务微信的cropID
  635. timestamp: "1608692903", // 必填,生成签名的时间戳
  636. nonceStr: "XKIvykvwOuAeIbl", // 必填,生成签名的随机串
  637. signature: "ad0c077e6b5fbfe0c9e5394703d8262a3bc21fc3", // 必填,签名,见附录1
  638. jsApiList: [
  639. "multiWindows_open",
  640. "multiWindows_close",
  641. "multiWindows_subscribe",
  642. "multiWindows_publish",
  643. "multiWindows_finish",
  644. "chooseImage",
  645. "scanQRCode",
  646. "hideOptionMenu",
  647. "shareWechatMessage",
  648. "shareAppMessage",
  649. "startAutoLBS",
  650. "stopAutoLBS",
  651. "onLocationChange",
  652. "onMenuShareAppMessage",
  653. "onMenuShareWechat",
  654. "previewFile",
  655. "openChatWithMsg",
  656. "ext_Database_Open",
  657. "ext_Database_Exec",
  658. "ext_Database_Query",
  659. "ext_Database_Close",
  660. "ext_ISCP_Init",
  661. "ext_ISCP_ConnectService",
  662. "ext_ISCP_GetLocalPort",
  663. "ext_ISCP_Close",
  664. "ext_ISCP_Status",
  665. "ext_screenControl_direction",
  666. "getLocation",
  667. "getZipAppDirectory",
  668. "multiWindows_open",
  669. "ext_DeviceInfo_GetInfo",
  670. "ext_DeviceInfo_version",
  671. "getAuthCode",
  672. ], // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  673. });
  674. });
  675. }