@tmsfe/tms-core 0.0.148 → 0.0.150

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tms-core",
3
- "version": "0.0.148",
3
+ "version": "0.0.150",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1 +1,2 @@
1
+ /* eslint-disable */
1
2
  !function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(t.JSEncrypt={})}(this,(function(t){"use strict";function r(t){return"0123456789abcdefghijklmnopqrstuvwxyz".charAt(t)}var i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";var e,o=function(t,r){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var i in r)r.hasOwnProperty(i)&&(t[i]=r[i])})(t,r)},n={decode:function(t){var r;if(void 0===e){var i="= \f\n\r\t \u2028\u2029";for(e=Object.create(null),r=0;r<64;++r)e["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r)]=r;for(r=0;r<9;++r)e[i.charAt(r)]=-1}var o=[],n=0,s=0;for(r=0;r<t.length;++r){var h=t.charAt(r);if("="==h)break;if(-1!=(h=e[h])){if(void 0===h)throw new Error("ico"+r);n|=h,4<=++s?(o[o.length]=n>>16,o[o.length]=n>>8&255,o[o.length]=255&n,s=n=0):n<<=6}}switch(s){case 1:throw new Error("bee");case 2:o[o.length]=n>>10;break;case 3:o[o.length]=n>>16,o[o.length]=n>>8&255}return o},re:/-----BEGIN [^-]+-----([A-Za-z0-9+\/=\s]+)-----END [^-]+-----|begin-base64[^\n]+\n([A-Za-z0-9+\/=\s]+)====/,unarmor:function(t){var r=n.re.exec(t);if(r)if(r[1])t=r[1];else{if(!r[2])throw new Error("ros");t=r[2]}return n.decode(t)}};var s=function(){function t(r,i){this.hexDigits="0123456789ABCDEF",r instanceof t?(this.enc=r.enc,this.pos=r.pos):(this.enc=r,this.pos=i)}return t.prototype.get=function(t){if(void 0===t&&(t=this.pos++),t>=this.enc.length)throw new Error("Requesting byte offset "+t+" on a stream of length "+this.enc.length);return"string"==typeof this.enc?this.enc.charCodeAt(t):this.enc[t]},t.prototype.hexByte=function(t){return this.hexDigits.charAt(t>>4&15)+this.hexDigits.charAt(15&t)},t.prototype.hexDump=function(t,r,i){for(var e="",o=t;o<r;++o)if(e+=this.hexByte(this.get(o)),!0!==i)switch(15&o){case 7:e+=" ";break;case 15:e+="\n";break;default:e+=" "}return e},t}(),h=function(){function t(t,r,i,e,o){if(!(e instanceof u))throw new Error("iv");this.stream=t,this.header=r,this.length=i,this.tag=e,this.sub=o}return t.prototype.posStart=function(){return this.stream.pos},t.prototype.posEnd=function(){return this.stream.pos+this.header+Math.abs(this.length)},t.prototype.toHexString=function(){return this.stream.hexDump(this.posStart(),this.posEnd(),!0)},t.decodeLength=function(t){var r=t.get(),i=127&r;if(i==r)return i;if(6<i)throw new Error("lns"+(t.pos-1));if(0===i)return null;for(var e=r=0;e<i;++e)r=256*r+t.get();return r},t.prototype.getHexStringValue=function(){var t=this.toHexString(),r=2*this.header,i=2*this.length;return t.substr(r,i)},t.decode=function(r){var i;i=r instanceof s?r:new s(r,0);var e=new s(i),o=new u(i),n=t.decodeLength(i),h=i.pos,f=h-e.pos,a=null,p=function(){var r=[];if(null!==n){for(var e=h+n;i.pos<e;)r[r.length]=t.decode(i);if(i.pos!=e)throw new Error("Content size is not correct for container starting at offset "+h)}else try{for(;;){var o=t.decode(i);if(o.tag.isEOC())break;r[r.length]=o}n=h-i.pos}catch(r){throw new Error("Exception while decoding undefined length content: "+r)}return r};if(o.tagConstructed)a=p();else if(o.isUniversal()&&(3==o.tagNumber||4==o.tagNumber))try{if(3==o.tagNumber&&0!=i.get())throw new Error("bsu");a=p();for(var c=0;c<a.length;++c)if(a[c].tag.isEOC())throw new Error("EOC")}catch(r){a=null}if(null===a){if(null===n)throw new Error("a"+h);i.pos=h+Math.abs(n)}return new t(e,f,n,o,a)},t}(),u=function(){function t(t){var r=t.get();if(this.tagClass=r>>6,this.tagConstructed=!!(32&r),this.tagNumber=31&r,31==this.tagNumber){for(var i=new y;r=t.get(),i.mulAdd(128,127&r),128&r;);this.tagNumber=i.simplify()}}return t.prototype.isUniversal=function(){return 0===this.tagClass},t.prototype.isEOC=function(){return 0===this.tagClass&&0===this.tagNumber},t}(),f=function(){function t(t,r,i){null!=t&&("number"==typeof t?this.fromNumber(t,r,i):null==r&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,r))}return t.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var i;if(16==t)i=4;else if(8==t)i=3;else if(2==t)i=1;else if(32==t)i=5;else{if(4!=t)return this.toRadix(t);i=2}var e,o=(1<<i)-1,n=!1,s="",h=this.t,u=this.DB-h*this.DB%i;if(0<h--)for(u<this.DB&&0<(e=this[h]>>u)&&(n=!0,s=r(e));0<=h;)u<i?(e=(this[h]&(1<<u)-1)<<i-u,e|=this[--h]>>(u+=this.DB-i)):(e=this[h]>>(u-=i)&o,u<=0&&(u+=this.DB,--h)),0<e&&(n=!0),n&&(s+=r(e));return n?s:"0"},t.prototype.abs=function(){return this.s<0?this.negate():this},t.prototype.compareTo=function(t){var r=this.s-t.s;if(0!=r)return r;var i=this.t;if(0!=(r=i-t.t))return this.s<0?-r:r;for(;0<=--i;)if(0!=(r=this[i]-t[i]))return r;return 0},t.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+S(this[this.t-1]^this.s&this.DM)},t.prototype.modPowInt=function(t,r){var i;return i=t<256||r.isEven()?new a(r):new p(r),this.exp(t,i)},t.prototype.copyTo=function(t){for(var r=this.t-1;0<=r;--r)t[r]=this[r];t.t=this.t,t.s=this.s},t.prototype.fromInt=function(t){this.t=1,this.s=t<0?-1:0,0<t?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0},t.prototype.fromString=function(r,i){var e;if(16==i)e=4;else if(8==i)e=3;else if(256==i)e=8;else if(2==i)e=1;else if(32==i)e=5;else{if(4!=i)return void this.fromRadix(r,i);e=2}this.t=0,this.s=0;for(var o=r.length,n=!1,s=0;0<=--o;){var h=8==e?255&+r[o]:b(r,o);h<0?"-"==r.charAt(o)&&(n=!0):(n=!1,0==s?this[this.t++]=h:s+e>this.DB?(this[this.t-1]|=(h&(1<<this.DB-s)-1)<<s,this[this.t++]=h>>this.DB-s):this[this.t-1]|=h<<s,(s+=e)>=this.DB&&(s-=this.DB))}8==e&&!!(128&+r[0])&&(this.s=-1,0<s&&(this[this.t-1]|=(1<<this.DB-s)-1<<s)),this.clamp(),n&&t.ZERO.subTo(this,this)},t.prototype.clamp=function(){for(var t=this.s&this.DM;0<this.t&&this[this.t-1]==t;)--this.t},t.prototype.dlShiftTo=function(t,r){var i;for(i=this.t-1;0<=i;--i)r[i+t]=this[i];for(i=t-1;0<=i;--i)r[i]=0;r.t=this.t+t,r.s=this.s},t.prototype.drShiftTo=function(t,r){for(var i=t;i<this.t;++i)r[i-t]=this[i];r.t=Math.max(this.t-t,0),r.s=this.s},t.prototype.lShiftTo=function(t,r){for(var i=t%this.DB,e=this.DB-i,o=(1<<e)-1,n=Math.floor(t/this.DB),s=this.s<<i&this.DM,h=this.t-1;0<=h;--h)r[h+n+1]=this[h]>>e|s,s=(this[h]&o)<<i;for(h=n-1;0<=h;--h)r[h]=0;r[n]=s,r.t=this.t+n+1,r.s=this.s,r.clamp()},t.prototype.rShiftTo=function(t,r){r.s=this.s;var i=Math.floor(t/this.DB);if(i>=this.t)r.t=0;else{var e=t%this.DB,o=this.DB-e,n=(1<<e)-1;r[0]=this[i]>>e;for(var s=i+1;s<this.t;++s)r[s-i-1]|=(this[s]&n)<<o,r[s-i]=this[s]>>e;0<e&&(r[this.t-i-1]|=(this.s&n)<<o),r.t=this.t-i,r.clamp()}},t.prototype.subTo=function(t,r){for(var i=0,e=0,o=Math.min(t.t,this.t);i<o;)e+=this[i]-t[i],r[i++]=e&this.DM,e>>=this.DB;if(t.t<this.t){for(e-=t.s;i<this.t;)e+=this[i],r[i++]=e&this.DM,e>>=this.DB;e+=this.s}else{for(e+=this.s;i<t.t;)e-=t[i],r[i++]=e&this.DM,e>>=this.DB;e-=t.s}r.s=e<0?-1:0,e<-1?r[i++]=this.DV+e:0<e&&(r[i++]=e),r.t=i,r.clamp()},t.prototype.multiplyTo=function(r,i){var e=this.abs(),o=r.abs(),n=e.t;for(i.t=n+o.t;0<=--n;)i[n]=0;for(n=0;n<o.t;++n)i[n+e.t]=e.am(0,o[n],i,n,0,e.t);i.s=0,i.clamp(),this.s!=r.s&&t.ZERO.subTo(i,i)},t.prototype.squareTo=function(t){for(var r=this.abs(),i=t.t=2*r.t;0<=--i;)t[i]=0;for(i=0;i<r.t-1;++i){var e=r.am(i,r[i],t,2*i,0,1);(t[i+r.t]+=r.am(i+1,2*r[i],t,2*i+1,e,r.t-i-1))>=r.DV&&(t[i+r.t]-=r.DV,t[i+r.t+1]=1)}0<t.t&&(t[t.t-1]+=r.am(i,r[i],t,2*i,0,1)),t.s=0,t.clamp()},t.prototype.divRemTo=function(r,i,e){var o=r.abs();if(!(o.t<=0)){var n=this.abs();if(n.t<o.t)return null!=i&&i.fromInt(0),void(null!=e&&this.copyTo(e));null==e&&(e=c());var s=c(),h=this.s,u=r.s,f=this.DB-S(o[o.t-1]);0<f?(o.lShiftTo(f,s),n.lShiftTo(f,e)):(o.copyTo(s),n.copyTo(e));var a=s.t,p=s[a-1];if(0!=p){var l=p*(1<<this.F1)+(1<a?s[a-2]>>this.F2:0),y=this.FV/l,m=(1<<this.F1)/l,g=1<<this.F2,v=e.t,d=v-a,b=null==i?c():i;for(s.dlShiftTo(d,b),0<=e.compareTo(b)&&(e[e.t++]=1,e.subTo(b,e)),t.ONE.dlShiftTo(a,b),b.subTo(s,s);s.t<a;)s[s.t++]=0;for(;0<=--d;){var T=e[--v]==p?this.DM:Math.floor(e[v]*y+(e[v-1]+g)*m);if((e[v]+=s.am(0,T,e,d,0,a))<T)for(s.dlShiftTo(d,b),e.subTo(b,e);e[v]<--T;)e.subTo(b,e)}null!=i&&(e.drShiftTo(a,i),h!=u&&t.ZERO.subTo(i,i)),e.t=a,e.clamp(),0<f&&e.rShiftTo(f,e),h<0&&t.ZERO.subTo(e,e)}}},t.prototype.invDigit=function(){if(this.t<1)return 0;var t=this[0];if(!(1&t))return 0;var r=3&t;return 0<(r=(r=(r=(r=r*(2-(15&t)*r)&15)*(2-(255&t)*r)&255)*(2-((65535&t)*r&65535))&65535)*(2-t*r%this.DV)%this.DV)?this.DV-r:-r},t.prototype.isEven=function(){return 0==(0<this.t?1&this[0]:this.s)},t.prototype.exp=function(r,i){if(4294967295<r||r<1)return t.ONE;var e=c(),o=c(),n=i.convert(this),s=S(r)-1;for(n.copyTo(e);0<=--s;)if(i.sqrTo(e,o),0<(r&1<<s))i.mulTo(o,n,e);else{var h=e;e=o,o=h}return i.revert(e)},t}(),a=(function(){function t(){}t.prototype.convert=function(t){return t},t.prototype.revert=function(t){return t},t.prototype.mulTo=function(t,r,i){t.multiplyTo(r,i)},t.prototype.sqrTo=function(t,r){t.squareTo(r)}}(),function(){function t(t){this.m=t}return t.prototype.convert=function(t){return t.s<0||0<=t.compareTo(this.m)?t.mod(this.m):t},t.prototype.revert=function(t){return t},t.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},t.prototype.mulTo=function(t,r,i){t.multiplyTo(r,i),this.reduce(i)},t.prototype.sqrTo=function(t,r){t.squareTo(r),this.reduce(r)},t}()),p=function(){function t(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t}return t.prototype.convert=function(t){var r=c();return t.abs().dlShiftTo(this.m.t,r),r.divRemTo(this.m,null,r),t.s<0&&0<r.compareTo(f.ZERO)&&this.m.subTo(r,r),r},t.prototype.revert=function(t){var r=c();return t.copyTo(r),this.reduce(r),r},t.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var r=0;r<this.m.t;++r){var i=32767&t[r],e=i*this.mpl+((i*this.mph+(t[r]>>15)*this.mpl&this.um)<<15)&t.DM;for(t[i=r+this.m.t]+=this.m.am(0,e,t,r,0,this.m.t);t[i]>=t.DV;)t[i]-=t.DV,t[++i]++}t.clamp(),t.drShiftTo(this.m.t,t),0<=t.compareTo(this.m)&&t.subTo(this.m,t)},t.prototype.mulTo=function(t,r,i){t.multiplyTo(r,i),this.reduce(i)},t.prototype.sqrTo=function(t,r){t.squareTo(r),this.reduce(r)},t}();!function(){function t(t){this.m=t,this.r2=c(),this.q3=c(),f.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t)}t.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var r=c();return t.copyTo(r),this.reduce(r),r},t.prototype.revert=function(t){return t},t.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);0<=t.compareTo(this.m);)t.subTo(this.m,t)},t.prototype.mulTo=function(t,r,i){t.multiplyTo(r,i),this.reduce(i)},t.prototype.sqrTo=function(t,r){t.squareTo(r),this.reduce(r)}}();function c(){return new f(null)}function l(t,r){return new f(t,r)}f.prototype.am=function(t,r,i,e,o,n){for(var s=16383&r,h=r>>14;0<=--n;){var u=16383&this[t],f=this[t++]>>14,a=h*u+f*s;o=((u=s*u+((16383&a)<<14)+i[e]+o)>>28)+(a>>14)+h*f,i[e++]=268435455&u}return o},f.prototype.DB=28,f.prototype.DM=268435455,f.prototype.DV=1<<28,f.prototype.FV=Math.pow(2,52),f.prototype.F1=24,f.prototype.F2=4;var m,g,v=[];for(m="0".charCodeAt(0),g=0;g<=9;++g)v[m++]=g;for(m="a".charCodeAt(0),g=10;g<36;++g)v[m++]=g;for(m="A".charCodeAt(0),g=10;g<36;++g)v[m++]=g;function b(t,r){var i=v[t.charCodeAt(r)];return null==i?-1:i}function T(t){var r=c();return r.fromInt(t),r}function S(t){var r,i=1;return 0!=(r=t>>>16)&&(t=r,i+=16),0!=(r=t>>8)&&(t=r,i+=8),0!=(r=t>>4)&&(t=r,i+=4),0!=(r=t>>2)&&(t=r,i+=2),0!=(r=t>>1)&&(t=r,i+=1),i}f.ZERO=T(0),f.ONE=T(1);var w,D,x=function(){function t(){this.i=0,this.j=0,this.S=[]}return t.prototype.init=function(t){var r,i,e;for(r=0;r<256;++r)this.S[r]=r;for(r=i=0;r<256;++r)i=i+this.S[r]+t[r%t.length]&255,e=this.S[r],this.S[r]=this.S[i],this.S[i]=e;this.i=0,this.j=0},t.prototype.next=function(){var t;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,t=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=t,this.S[t+this.S[this.i]&255]},t}(),E=256,A=null;if(null==A){A=[];D=0;!function(t){for(var r=0,i=t.length;r<i;r++)t[r]=Math.floor(256*Math.random())}(E=new Uint32Array(256))}function B(){if(null==w){for(w=new x;D<E;){var t=Math.floor(65536*Math.random());A[D++]=255&t}for(w.init(A),D=0;D<A.length;++D)A[D]=0;D=0}return w.next()}var _=function(){function t(){}return t.prototype.nextBytes=function(t){for(var r=0;r<t.length;++r)t[r]=B()},t}(),M=function(){function t(){this.n=null,this.e=0,this.d=null,this.p=null,this.q=null,this.dmp1=null,this.dmq1=null,this.coeff=null}return t.prototype.doPublic=function(t){return t.modPowInt(this.e,this.n)},t.prototype.setPublic=function(t,r){null!=t&&null!=r&&0<t.length&&0<r.length?(this.n=l(t,16),this.e=parseInt(r,16)):console.error("Invalid RSA public key")},t.prototype.encrypt=function(t){var r=function(t,r){if(r<t.length+11)return console.error("Message too long for RSA"),null;for(var i=[],e=t.length-1;0<=e&&0<r;){var o=t.charCodeAt(e--);o<128?i[--r]=o:127<o&&o<2048?(i[--r]=63&o|128,i[--r]=o>>6|192):(i[--r]=63&o|128,i[--r]=o>>6&63|128,i[--r]=o>>12|224)}i[--r]=0;for(var n=new _,s=[];2<r;){for(s[0]=0;0==s[0];)n.nextBytes(s);i[--r]=s[0]}return i[--r]=2,i[--r]=0,new f(i)}(t,this.n.bitLength()+7>>3);if(null==r)return null;var i=this.doPublic(r);if(null==i)return null;var e=i.toString(16);return 1&e.length?"0"+e:e},t}(),O=function(t){function r(i){var e=t.call(this)||this;return i&&("string"==typeof i?e.parseKey(i):r.hasPublicKeyProperty(i)&&e.parsePropertiesFrom(i)),e}return function(t,r){function i(){this.constructor=t}o(t,r),t.prototype=null===r?Object.create(r):(i.prototype=r.prototype,new i)}(r,t),r.prototype.parseKey=function(t){try{var r=0,i=0,e=/^\s*(?:[0-9A-Fa-f][0-9A-Fa-f]\s*)+$/.test(t)?d(t):n.unarmor(t),o=h.decode(e);if(3===o.sub.length&&(o=o.sub[2].sub[0]),9===o.sub.length){r=o.sub[1].getHexStringValue(),this.n=l(r,16),i=o.sub[2].getHexStringValue(),this.e=parseInt(i,16);var s=o.sub[3].getHexStringValue();this.d=l(s,16);var u=o.sub[4].getHexStringValue();this.p=l(u,16);var f=o.sub[5].getHexStringValue();this.q=l(f,16);var a=o.sub[6].getHexStringValue();this.dmp1=l(a,16);var p=o.sub[7].getHexStringValue();this.dmq1=l(p,16);var c=o.sub[8].getHexStringValue();this.coeff=l(c,16)}else{if(2!==o.sub.length)return!1;var y=o.sub[1].sub[0];r=y.sub[0].getHexStringValue(),this.n=l(r,16),i=y.sub[1].getHexStringValue(),this.e=parseInt(i,16)}return!0}catch(t){return!1}},r.wordwrap=function(t,r){if(!t)return t;var i="(.{1,"+(r=r||64)+"})( +|$\n?)|(.{1,"+r+"})";return t.match(RegExp(i,"g")).join("\n")},r.hasPublicKeyProperty=function(t){return(t=t||{}).hasOwnProperty("n")&&t.hasOwnProperty("e")},r}(M),V=function(){function t(t){t=t||{},this.default_key_size=parseInt(t.default_key_size,10)||1024,this.default_public_exponent=t.default_public_exponent||"010001",this.log=t.log||!1,this.key=null}return t.prototype.setKey=function(t){this.log&&this.key&&console.warn("a"),this.key=new O(t)},t.prototype.setPublicKey=function(t){this.setKey(t)},t.prototype.encrypt=function(t){try{return function(t){var r,e,o="";for(r=0;r+3<=t.length;r+=3)e=parseInt(t.substring(r,r+3),16),o+=i.charAt(e>>6)+i.charAt(63&e);for(r+1==t.length?(e=parseInt(t.substring(r,r+1),16),o+=i.charAt(e<<2)):r+2==t.length&&(e=parseInt(t.substring(r,r+2),16),o+=i.charAt(e>>2)+i.charAt((3&e)<<4));0<(3&o.length);)o+="=";return o}(this.getKey().encrypt(t))}catch(t){return!1}},t.prototype.getKey=function(t){if(!this.key){if(this.key=new O,t&&"[object Function]"==={}.toString.call(t))return void this.key.generateAsync(this.default_key_size,this.default_public_exponent,t);this.key.generate(this.default_key_size,this.default_public_exponent)}return this.key},t}();t.JSEncrypt=V,t.default=V,Object.defineProperty(t,"__esModule",{value:!0})}));
package/src/request.js CHANGED
@@ -15,6 +15,7 @@ import encryptObj from './encrypt';
15
15
  import reporter from './report/index';
16
16
 
17
17
  const logger = wx.getLogManager({});
18
+ let refreshPromise = null;
18
19
 
19
20
  /**
20
21
  * 用于序列化需要签名的参数
@@ -355,6 +356,10 @@ export default class Request {
355
356
  !!wx.$_publicKey, Request.requestEncryptOpen, path,
356
357
  );
357
358
  }
359
+ // 如果是获取pubKey的接口,但是没带userId, 则需要取消这次请求
360
+ if (path.indexOf('basic/crypto/lastkey') > -1 && !data.userId) {
361
+ return;
362
+ }
358
363
  return new Promise((resolve, reject) => {
359
364
  wx.request({
360
365
  url: path,
@@ -373,15 +378,31 @@ export default class Request {
373
378
  }
374
379
 
375
380
  async refreshEncryptKey() {
376
- try {
377
- const requestParam = await composeParam({}, true, {});
378
- const data = sign(requestParam, this.secretKey);
379
- const finalUrl = this.makeUrl('basic/crypto/lastkey');
380
- const res = await this.wxRequest(finalUrl, 'GET', {}, data, true, data.seqId);
381
- encryptObj.updateDecryptKey(res.data.resData);
382
- } catch (e) {
383
- encryptObj.updateDecryptKey(null);
381
+ if (wx.$_encrypt_refreshDisable) {
382
+ return false;
384
383
  }
384
+ if (!refreshPromise) {
385
+ refreshPromise = new Promise(async (resolve) => {
386
+ try {
387
+ const requestParam = await composeParam({}, true, {});
388
+ const data = sign(requestParam, this.secretKey);
389
+ const finalUrl = this.makeUrl('basic/crypto/lastkey');
390
+ const res = await this.wxRequest(finalUrl, 'GET', {}, data, true, data.seqId);
391
+ const success = res.data.errCode === 0;
392
+ if (!success) {
393
+ // 如果请求失败,则停止刷新加密秘钥,运行时永久关闭
394
+ wx.$_encrypt_refreshDisable = true;
395
+ }
396
+ encryptObj.updateDecryptKey(res.data.resData);
397
+ resolve(success);
398
+ } catch (e) {
399
+ encryptObj.updateDecryptKey(null);
400
+ resolve(false);
401
+ }
402
+ refreshPromise = null;
403
+ });
404
+ }
405
+ return refreshPromise;
385
406
  }
386
407
 
387
408
  // 如果全局请求加密开关关闭 || 当前请求内容不满足加密规则(publickey不为空且走sinan网关且非性能上报埋点)
@@ -405,12 +426,13 @@ export default class Request {
405
426
  wx.$_publicKey = null;
406
427
  return false;
407
428
  }
429
+ let refreshSuccess = true;
408
430
  // 打开开关,如果当前是关闭状态,则需要刷新加密key
409
431
  if (forceRefresh || !wx.$_publicKey) {
410
- await this.refreshEncryptKey();
432
+ refreshSuccess = await this.refreshEncryptKey();
411
433
  }
412
434
  this.dealEncryptionSwitching = false;
413
- return true;
435
+ return refreshSuccess;
414
436
  }
415
437
 
416
438
  /**
@@ -1,13 +0,0 @@
1
- import reporter from './report/index';
2
-
3
- async function loadPkg() {
4
- return new Promise((resolve) => {
5
- require.async('../../../modules/encrypt/init.js').then(pkg => {
6
- resolve(pkg.default);
7
- }).catch((err) => {
8
- reporter.reportPerformance('request_encrypt_log', 'main', 'load_encrypt_file_fail', err);
9
- });
10
- });
11
- }
12
-
13
- export default loadPkg;