utils.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. import store from '../store/index.js'
  2. import qs from 'qs'
  3. // const gatewayUrl = "http://192.168.1.105:8082/";
  4. const gatewayUrl = "https://kptyun.cn/";
  5. var requestTask = null
  6. function checkStatus(response) {
  7. // console.log(response)
  8. if (response.data.code == "1000000009" || response.data.code == "1000000010") {
  9. store.commit('logout')
  10. //#ifndef H5
  11. uni.showModal({
  12. title: '提示',
  13. content: '登录失效,请重新登录',
  14. cancelText: "暂不登录",
  15. confirmText: "去登录",
  16. success(res) {
  17. if (res.confirm) {
  18. uni.navigateTo({
  19. url: '/pages/login/login',
  20. })
  21. } else if (res.cancel) {
  22. console.log('用户点击取消')
  23. }
  24. }
  25. })
  26. //#endif
  27. //#ifdef H5
  28. //alert("aaaa")
  29. // window.location.reload()
  30. if (util.isWeiXin()) {
  31. let baseUrl = "https://open.weixin.qq.com/connect/oauth2/authorize#wechat_redirect";
  32. let redirectUri = util.appendParams(baseUrl, {
  33. 'appid': 'wx63ae87efa44fc305',
  34. 'redirect_uri': encodeURIComponent(window.location.href),
  35. 'response_type': 'code',
  36. 'scope': 'snsapi_userinfo',
  37. 'state': 'hello-world',
  38. });
  39. window.location.replace(redirectUri);
  40. // const url =
  41. // 'https://pailiying.com/livephoto/livephoto/getwxcode.html?appid=wx63ae87efa44fc305&scope=snsapi_userinfo&state=hello-world&redirect_uri=' +
  42. // encodeURI(window.location.href)
  43. // window.location.replace(url);
  44. }
  45. //#endif
  46. }
  47. // loading
  48. // 如果http状态码正常,则直接返回数据
  49. if (response && (response.statusCode === 200)) {
  50. return response.data;
  51. } else {
  52. // uni.showToast({
  53. // icon: "none",
  54. // mask: true,
  55. // title: "网络异常,请稍后再试"
  56. // })
  57. }
  58. }
  59. function checkCode(res) {
  60. // 如果code异常(这里已经包括网络错误,服务器错误,后端抛出的错误),可以弹出一个错误提示,告诉用户
  61. // uni.showToast({
  62. // icon: "none",
  63. // mask: true,
  64. // title: "网络异常,请稍后再试"
  65. // })
  66. }
  67. let util = {
  68. gatewayUrl: gatewayUrl,
  69. postForm(url, data, header) {
  70. let _url = '';
  71. if (url.indexOf('http://') != -1) {
  72. _url = url
  73. } else {
  74. _url = gatewayUrl + url
  75. }
  76. const headers = header || {};
  77. return new Promise((resolve, reject) => {
  78. uni.request({
  79. method: 'post',
  80. url: _url,
  81. data: qs.stringify(data),
  82. header: {
  83. ...headers,
  84. 'X-Requested-With': 'XMLHttpRequest',
  85. 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
  86. "token": uni.getStorageSync("userInfo") ? uni.getStorageSync("userInfo").token :
  87. ""
  88. },
  89. success: (res => {
  90. resolve(checkStatus(res))
  91. }),
  92. fail: (res => {
  93. reject(checkCode(res))
  94. })
  95. })
  96. })
  97. },
  98. postJson(url, data, header) {
  99. let _url = '';
  100. if(requestTask && url=='/pailiying-user/v1/user/getPhotoLiveImgList'){
  101. requestTask.abort()
  102. requestTask = null
  103. }
  104. if (url.indexOf('http://') != -1) {
  105. _url = url
  106. } else {
  107. _url = gatewayUrl + url
  108. }
  109. const headers = header || {};
  110. // console.log(uni.getStorageSync("userInfo"))
  111. return new Promise((resolve, reject) => {
  112. requestTask = uni.request({
  113. method: 'post',
  114. url: _url,
  115. data, // post 请求时带的参数
  116. header: Object.assign({
  117. 'X-Requested-With': 'XMLHttpRequest',
  118. 'content-type': 'application/json; charset=UTF-8',
  119. "token": uni.getStorageSync("userInfo") ? uni.getStorageSync("userInfo")
  120. .token : ""
  121. }, headers),
  122. success: (res => {
  123. requestTask = null
  124. resolve(checkStatus(res))
  125. }),
  126. fail: (res => {
  127. requestTask = null
  128. reject(checkCode(res))
  129. })
  130. })
  131. })
  132. },
  133. get(url, data, header) {
  134. let _url = '';
  135. if (url.indexOf('/api/') != -1) {
  136. _url = url
  137. } else {
  138. _url = gatewayUrl + url
  139. }
  140. const headers = header || {};
  141. return new Promise((resolve, reject) => {
  142. uni.request({
  143. method: 'get',
  144. url: _url,
  145. data, // get 请求时带的参数
  146. header: Object.assign({
  147. 'X-Requested-With': 'XMLHttpRequest',
  148. 'Accept': 'application/json, text/plain, */*',
  149. 'content-type': ' ',
  150. "token": uni.getStorageSync("userInfo") ? uni.getStorageSync(
  151. "userInfo").token : ""
  152. }, headers),
  153. success: (res => {
  154. resolve(checkStatus(res))
  155. }),
  156. fail: (res => {
  157. reject(checkCode(res))
  158. })
  159. })
  160. })
  161. },
  162. combineFromParamForNull: (param, needFormStyle) => { //组合参数
  163. const params = {};
  164. for (var i in param) {
  165. if (param[i] != null && param[i] != 'null') {
  166. params[i] = param[i]
  167. }
  168. }
  169. return params
  170. },
  171. getLocalTime(time) { //将时间错转化成2010-10-20 10:00:00
  172. const now = new Date(time)
  173. const year = now.getFullYear();
  174. var month = now.getMonth() + 1;
  175. if (month < 10) month = "0" + month;
  176. var date = now.getDate();
  177. if (date < 10) date = "0" + date;
  178. var hour = now.getHours();
  179. if (hour < 10) hour = "0" + hour;
  180. var minute = now.getMinutes();
  181. if (minute < 10) minute = "0" + minute;
  182. var second = now.getSeconds();
  183. if (second < 10) second = "0" + second;
  184. return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
  185. },
  186. getLocalTime2(time) { //将时间错转化成2010-10-20
  187. const now = new Date(time)
  188. const year = now.getFullYear();
  189. var month = now.getMonth() + 1;
  190. if (month < 10) month = "0" + month;
  191. var date = now.getDate();
  192. if (date < 10) date = "0" + date;
  193. return year + "-" + month + "-" + date
  194. },
  195. getLocalTime3(time) { //将时间错转化成 10:00:00
  196. const now = new Date(time)
  197. const year = now.getFullYear();
  198. var month = now.getMonth() + 1;
  199. if (month < 10) month = "0" + month;
  200. var date = now.getDate();
  201. if (date < 10) date = "0" + date;
  202. var hour = now.getHours();
  203. if (hour < 10) hour = "0" + hour;
  204. var minute = now.getMinutes();
  205. if (minute < 10) minute = "0" + minute;
  206. var second = now.getSeconds();
  207. if (second < 10) second = "0" + second;
  208. return hour + ":" + minute + ":" + second;
  209. },
  210. getLocalTime4(time) { //将时间错转化成 10:00
  211. const now = new Date(time)
  212. const year = now.getFullYear();
  213. var month = now.getMonth() + 1;
  214. if (month < 10) month = "0" + month;
  215. var date = now.getDate();
  216. if (date < 10) date = "0" + date;
  217. var hour = now.getHours();
  218. if (hour < 10) hour = "0" + hour;
  219. var minute = now.getMinutes();
  220. if (minute < 10) minute = "0" + minute;
  221. var second = now.getSeconds();
  222. if (second < 10) second = "0" + second;
  223. return minute + ":" + second;
  224. },
  225. isWeiXin() {
  226. let ua = window.navigator.userAgent.toLowerCase();
  227. if (ua.match(/MicroMessenger/i) == 'micromessenger') {
  228. return true;
  229. } else {
  230. return false;
  231. }
  232. },
  233. isAlipay() {
  234. let userAgent = navigator.userAgent.toLowerCase();
  235. if (userAgent.match(/Alipay/i) == "alipay") {
  236. return true;
  237. } else {
  238. return false;
  239. }
  240. },
  241. gethtml(value) {
  242. if (value) {
  243. let a = value.replace(/<img([\s\w"-=\/\.:;]+)((?:(style="[^"]+")))/ig,
  244. '<img$1 style="max-width:100%;height:auto;float:none;display:block;')
  245. .replace(/<p([\s\w"=\/\.:;]+)((?:(style="[^"]+")))/ig, '<p')
  246. .replace(/<p>/ig, '<p style="font-size: 15Px; line-height: 25Px;">')
  247. .replace(/<img([\s\w"-=\/\.:;]+)((?:(height="[^"]+")))/ig, '<img$1 ')
  248. .replace(/<img([\s\w"-=\/\.:;]+)((?:(width="[^"]+")))/ig, '<img$1 ')
  249. .replace(/<img([\s\w"-=\/\.:;]+)((?:(alt="[^"]+")))/ig, '<img$1')
  250. .replace(/<img([\s\w"-=\/\.:;]+)/ig, '<img$1 "');
  251. return a
  252. } else {
  253. return ""
  254. }
  255. },
  256. //登录校验
  257. checkLogin(callback) {
  258. let userInfo = uni.getStorageSync('userInfo') || '';
  259. if (userInfo.token) {
  260. callback()
  261. } else {
  262. // #ifdef H5
  263. if (this.isWeiXin()) {
  264. // h5_address
  265. console.log('h5_address==>',uni.getStorageSync("h5_address"))
  266. // const url = 'https://pailiying.com/livephoto/getwxcode.html?appid=wx63ae87efa44fc305&scope=snsapi_userinfo&state=hello-world&redirect_uri=' + encodeURI(window.location.href)
  267. const url = uni.getStorageSync("h5_address") + '/getwxcode.html?appid=wx63ae87efa44fc305&scope=snsapi_userinfo&state=hello-world&redirect_uri=' + encodeURI(window.location.href)
  268. window.location.replace(url);
  269. }
  270. // #endif
  271. }
  272. },
  273. payorder(aa, callback) {
  274. let that = this
  275. let msg = aa
  276. // #ifdef H5
  277. if (that.isWeiXin()) {
  278. that.postJson(msg.url, that.combineFromParamForNull(msg.parms)).then(function(res) {
  279. uni.hideLoading()
  280. if (res.status == 1) {
  281. uni.showLoading({
  282. title: '正在支付',
  283. mask: true
  284. })
  285. if (typeof WeixinJSBridge == "undefined") {
  286. if (document.addEventListener) {
  287. document.addEventListener('WeixinJSBridgeReady', that.onBridgeReady(res.data,
  288. callback), false);
  289. } else if (document.attachEvent) {
  290. document.attachEvent('WeixinJSBridgeReady', that.onBridgeReady(res.data,
  291. callback));
  292. document.attachEvent('onWeixinJSBridgeReady', that.onBridgeReady(res.data,
  293. callback));
  294. }
  295. } else {
  296. that.onBridgeReady(res.data, callback);
  297. }
  298. } else {
  299. uni.showModal({
  300. title: '',
  301. content: "付款失败",
  302. showCancel: false,
  303. })
  304. }
  305. },
  306. function(fail) {
  307. uni.hideLoading()
  308. uni.showToast({
  309. title: "付款失败",
  310. icon: "none"
  311. })
  312. }
  313. )
  314. } else if (utils.isAlipay()) {
  315. parms.payType = 2
  316. utils.postJson(url, utils.combineFromParamForNull(parms), {}).then(function(res) {
  317. uni.hideLoading()
  318. if (res.status == '0') {
  319. if (typeof(res.data) === 'string') {
  320. that.tradeNO = JSON.parse(res.data).tradeNO;
  321. } else {
  322. that.tradeNO = res.data.tradeNo;
  323. }
  324. if (res.data.code_url) {
  325. // uni.navigateTo({
  326. // url: "../webview/webview?urls=" + res.data.code_url
  327. // })
  328. } else {
  329. uni.showLoading({
  330. title: '正在跳转支付宝支付',
  331. mask: true
  332. })
  333. if (window.AlipayJSBridge) {
  334. that.onAliBridgeReady && that.onAliBridgeReady();
  335. } else {
  336. // 如果没有注入则监听注入的事件
  337. document.addEventListener('AlipayJSBridgeReady', that.onAliBridgeReady, false);
  338. }
  339. }
  340. } else {
  341. that.$api.msg(res.msg);
  342. uni.showModal({
  343. title: '',
  344. content: "付款失败",
  345. showCancel: false,
  346. })
  347. }
  348. },
  349. function(fail) {
  350. uni.hideLoading()
  351. that.$api.msg(fail);
  352. }
  353. )
  354. } else {
  355. alert("请在支付宝或者微信中扫码")
  356. }
  357. // #endif
  358. //#ifdef MP-WEIXIN
  359. that.postJson(msg.url, that.combineFromParamForNull(msg.parms),
  360. msg.heard
  361. ).then(function(res) {
  362. uni.hideLoading()
  363. if (res.code == '0000') {
  364. uni.showLoading({
  365. title: '正在跳转微信支付',
  366. mask: true
  367. })
  368. const payParam = {
  369. appId: res.data.appId,
  370. nonceStr: res.data.nonceStr,
  371. package: res.data.package,
  372. timeStamp: res.data.timeStamp + "",
  373. signType: res.data.signType,
  374. paySign: res.data.paySign,
  375. }
  376. uni.requestPayment({
  377. provider: 'wxpay',
  378. //#ifdef MP-WEIXIN
  379. ...payParam,
  380. //#endif
  381. //#ifdef APP-PLUS
  382. orderInfo: payParam,
  383. //#endif
  384. success: function(resq) {
  385. callback()
  386. },
  387. fail: function(fails) {
  388. uni.hideLoading()
  389. uni.showToast({
  390. title: "付款失败",
  391. icon: "none"
  392. })
  393. console.log("支付过程失败", fails);
  394. // that.$api.msg(JSON.stringify(fails))
  395. },
  396. complete: function(res) {
  397. uni.hideLoading()
  398. console.log("支付过程结束")
  399. }
  400. });
  401. } else {
  402. uni.showModal({
  403. title: '',
  404. content: "付款失败",
  405. showCancel: false,
  406. })
  407. }
  408. },
  409. function(fail) {
  410. uni.hideLoading()
  411. that.$api.msg(fail);
  412. }
  413. )
  414. //#endif
  415. },
  416. onAliBridgeReady() { //唤起支付宝支付
  417. const me = this;
  418. AlipayJSBridge.call("tradePay", {
  419. tradeNO: me.tradeNO
  420. }, function(res) {
  421. if (res.resultCode == 9000) {
  422. uni.redirectTo({
  423. url: "/pages/shopSuccess/shopSuccess"
  424. })
  425. } else {
  426. uni.showModal({
  427. title: '',
  428. content: "付款失败",
  429. showCancel: false,
  430. })
  431. }
  432. });
  433. },
  434. appendParams(url, params) {
  435. if (params) {
  436. var baseWithSearch = url.split('#')[0];
  437. var hash = url.split('#')[1];
  438. for (var key in params) {
  439. var attrValue = params[key];
  440. if (attrValue !== undefined) {
  441. var newParam = key + "=" + attrValue;
  442. if (baseWithSearch.indexOf('?') > 0) {
  443. var oldParamReg = new RegExp('^' + key + '=[-%.!~*\'\(\)\\w]*', 'g');
  444. if (oldParamReg.test(baseWithSearch)) {
  445. baseWithSearch = baseWithSearch.replace(oldParamReg, newParam);
  446. } else {
  447. baseWithSearch += "&" + newParam;
  448. }
  449. } else {
  450. baseWithSearch += "?" + newParam;
  451. }
  452. }
  453. }
  454. if (hash) {
  455. url = baseWithSearch + '#' + hash;
  456. } else {
  457. url = baseWithSearch;
  458. }
  459. }
  460. return url;
  461. },
  462. onBridgeReady(datas, callback) { //唤起微信支付
  463. const me = this;
  464. WeixinJSBridge.invoke(
  465. 'getBrandWCPayRequest', {
  466. "appId": datas.appId,
  467. "nonceStr": datas.nonceStr,
  468. "package": datas.package,
  469. "paySign": datas.paySign,
  470. "signType": datas.signType,
  471. "timeStamp": datas.timeStamp
  472. },
  473. function(res) {
  474. alert(JSON.stringify(res))
  475. uni.hideLoading();
  476. if (res.err_msg ==
  477. "get_brand_wcpay_request:ok") { // 使用以上方式判断前端返回,微信团队郑重提示:res.err_msg将在用户支付成功后返回 ok,但并不保证它绝对可靠。
  478. callback()
  479. } else if (res.err_msg == "get_brand_wcpay_request:cancel") {
  480. uni.showModal({
  481. title: '',
  482. content: "付款失败",
  483. showCancel: false,
  484. })
  485. } else if (res.err_msg == "get_brand_wcpay_request:fail") {
  486. uni.showModal({
  487. title: '',
  488. content: "付款失败",
  489. showCancel: false,
  490. })
  491. } else {
  492. uni.showModal({
  493. title: '',
  494. content: "付款失败",
  495. showCancel: false,
  496. })
  497. }
  498. }
  499. )
  500. },
  501. //校验手机号
  502. checkphone(n) {
  503. var myreg =
  504. /^(((14[0-9]{1})|(16[0-9]{1})|(17[0-9]{1})|(13[0-9]{1})|(19[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
  505. if (n && myreg.test(n)) {
  506. return true
  507. } else {
  508. return false
  509. }
  510. },
  511. //正整数校验
  512. checkNumber(n) {
  513. var myreg = /(^[1-9]\d*$)/;
  514. if (n && myreg.test(n)) {
  515. return true
  516. } else {
  517. return false
  518. }
  519. },
  520. // 校验金额
  521. checkMoney(n) {
  522. var myreg = /(^[1-9]{1}[0-9]*$)|(^[0-9]*\.[0-9]{1,2}$)/;
  523. if (n && myreg.test(n)) {
  524. return true
  525. } else {
  526. return false
  527. }
  528. },
  529. // 不为空校验
  530. checkstr(n) {
  531. var myreg = /\S/;
  532. if (n && myreg.test(n)) {
  533. return true
  534. } else {
  535. return false
  536. }
  537. },
  538. checkPwd(n) { //校验密码6-16位至少有一个数字字母
  539. var myreg =
  540. /^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?![,\!@$.#%\'\+\*\-:;^_`]+$)[,\!@$.#%\'\+\*\-:;^_`0-9A-Za-z]{6,16}$/;
  541. if (n && myreg.test(n)) {
  542. return true
  543. } else {
  544. return false
  545. }
  546. },
  547. Base64() {
  548. // 私钥
  549. let _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  550. // 加密
  551. this.encode = function (input) {
  552. var output = "";
  553. var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
  554. var i = 0;
  555. input = _utf8_encode(input);
  556. while (i < input.length) {
  557. chr1 = input.charCodeAt(i++);
  558. chr2 = input.charCodeAt(i++);
  559. chr3 = input.charCodeAt(i++);
  560. enc1 = chr1 >> 2;
  561. enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
  562. enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
  563. enc4 = chr3 & 63;
  564. if (isNaN(chr2)) {
  565. enc3 = enc4 = 64;
  566. } else if (isNaN(chr3)) {
  567. enc4 = 64;
  568. }
  569. output = output +
  570. _keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
  571. _keyStr.charAt(enc3) + _keyStr.charAt(enc4);
  572. }
  573. return output;
  574. }
  575. // 解密
  576. this.decode = (input)=> {
  577. var output = "";
  578. var chr1, chr2, chr3;
  579. var enc1, enc2, enc3, enc4;
  580. var i = 0;
  581. if (input==undefined||input==null){
  582. }else {
  583. input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
  584. while (i < input.length) {
  585. enc1 = _keyStr.indexOf(input.charAt(i++));
  586. enc2 = _keyStr.indexOf(input.charAt(i++));
  587. enc3 = _keyStr.indexOf(input.charAt(i++));
  588. enc4 = _keyStr.indexOf(input.charAt(i++));
  589. chr1 = (enc1 << 2) | (enc2 >> 4);
  590. chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
  591. chr3 = ((enc3 & 3) << 6) | enc4;
  592. output = output + String.fromCharCode(chr1);
  593. if (enc3 != 64) {
  594. output = output + String.fromCharCode(chr2);
  595. }
  596. if (enc4 != 64) {
  597. output = output + String.fromCharCode(chr3);
  598. }
  599. }
  600. output = _utf8_decode(output);
  601. return output;
  602. }
  603. }
  604. // private method for UTF-8 encoding
  605. let _utf8_encode = (string)=> {
  606. string = string.replace(/\r\n/g,"\n");
  607. var utftext = "";
  608. for (var n = 0; n < string.length; n++) {
  609. var c = string.charCodeAt(n);
  610. if (c < 128) {
  611. utftext += String.fromCharCode(c);
  612. } else if((c > 127) && (c < 2048)) {
  613. utftext += String.fromCharCode((c >> 6) | 192);
  614. utftext += String.fromCharCode((c & 63) | 128);
  615. } else {
  616. utftext += String.fromCharCode((c >> 12) | 224);
  617. utftext += String.fromCharCode(((c >> 6) & 63) | 128);
  618. utftext += String.fromCharCode((c & 63) | 128);
  619. }
  620. }
  621. return utftext;
  622. }
  623. // private method for UTF-8 decoding
  624. let _utf8_decode = (utftext)=> {
  625. var string = "";
  626. var i = 0;
  627. var c = c1 = c2 = 0;
  628. var c1 = 0;
  629. var c2 = 0;
  630. var c3 = 0;
  631. while ( i < utftext.length ) {
  632. c = utftext.charCodeAt(i);
  633. if (c < 128) {
  634. string += String.fromCharCode(c);
  635. i++;
  636. } else if((c > 191) && (c < 224)) {
  637. c2 = utftext.charCodeAt(i+1);
  638. string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
  639. i += 2;
  640. } else {
  641. c2 = utftext.charCodeAt(i+1);
  642. c3 = utftext.charCodeAt(i+2);
  643. string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
  644. i += 3;
  645. }
  646. }
  647. return string;
  648. }
  649. },
  650. promisify: api => {
  651. return (options, ...params) => {
  652. return new Promise((resolve, reject) => {
  653. const extras = {
  654. success: resolve,
  655. fail: reject
  656. }
  657. api({
  658. ...options,
  659. ...extras
  660. }, ...params)
  661. })
  662. }
  663. }
  664. };
  665. export default util;