1?"loop "+(t.loop-i)+": ":"")+"SHP["+(e?"rp1":"rp2")+"]",o)}t.loop=1}function gn(e,t){const n=t.stack,o=e?t.rp1:t.rp2,r=(e?t.z0:t.z1)[o],s=t.fv,a=t.pv,i=n.pop(),l=t.z2[t.contours[i]];let c=l;exports.DEBUG&&console.log(t.step,"SHC["+e+"]",i);const u=a.distance(r,r,!1,!0);do{c!==r&&s.setRelative(c,c,u,a),c=c.nextPointOnContour}while(c!==l)}function mn(e,t){const n=t.stack,o=e?t.rp1:t.rp2,r=(e?t.z0:t.z1)[o],s=t.fv,a=t.pv,i=n.pop();let l,c;switch(exports.DEBUG&&console.log(t.step,"SHZ["+e+"]",i),i){case 0:l=t.tZone;break;case 1:l=t.gZone;break;default:throw new Error("Invalid zone")}const u=a.distance(r,r,!1,!0),p=l.length-2;for(let e=0;e",i),t.stack.push(Math.round(64*i))}function xn(e,t){const n=t.stack,o=n.pop(),r=t.fv,s=t.pv,a=t.ppem,i=t.deltaBase+16*(e-1),l=t.deltaShift,c=t.z0;exports.DEBUG&&console.log(t.step,"DELTAP["+e+"]",o,n);for(let e=0;e>4)!==a)continue;let u=(15&o)-8;u>=0&&u++,exports.DEBUG&&console.log(t.step,"DELTAPFIX",e,"by",u*l);const p=c[e];r.setRelative(p,p,u*l,s)}}function Un(e,t){const n=t.stack,o=n.pop();exports.DEBUG&&console.log(t.step,"ROUND[]"),n.push(64*t.round(o/64))}function Tn(e,t){const n=t.stack,o=n.pop(),r=t.ppem,s=t.deltaBase+16*(e-1),a=t.deltaShift;exports.DEBUG&&console.log(t.step,"DELTAC["+e+"]",o,n);for(let e=0;e>4)!==r)continue;let i=(15&o)-8;i>=0&&i++;const l=i*a;exports.DEBUG&&console.log(t.step,"DELTACFIX",e,"by",l),t.cvt[e]+=l}}function En(e,t){const n=t.stack,o=n.pop(),r=n.pop(),s=t.z2[o],a=t.z1[r];let i,l;exports.DEBUG&&console.log("SDPVTL["+e+"]",o,r),e?(i=s.y-a.y,l=a.x-s.x):(i=a.x-s.x,l=a.y-s.y),t.dpv=Kt(i,l)}function On(e,t){const n=t.stack,o=t.prog;let r=t.ip;exports.DEBUG&&console.log(t.step,"PUSHB["+e+"]");for(let t=0;t=0?1:-1,m=Math.abs(m),e&&(v=s.cvt[i],o&&Math.abs(m-v)":"_")+(o?"R":"_")+(0===r?"Gr":1===r?"Bl":2===r?"Wh":"")+"]",e?i+"("+s.cvt[i]+","+v+")":"",l,"(d =",g,"->",y*m,")"),s.rp1=s.rp0,s.rp2=l,t&&(s.rp0=l)}function Rn(e){(e=e||{}).empty||(Nt(e.familyName,"When creating a new Font object, familyName is required."),Nt(e.styleName,"When creating a new Font object, styleName is required."),Nt(e.unitsPerEm,"When creating a new Font object, unitsPerEm is required."),Nt(e.ascender,"When creating a new Font object, ascender is required."),Nt(e.descender,"When creating a new Font object, descender is required."),Nt(e.descender<0,"Descender should be negative (e.g. -512)."),this.names={fontFamily:{en:e.familyName||" "},fontSubfamily:{en:e.styleName||" "},fullName:{en:e.fullName||e.familyName+" "+e.styleName},postScriptName:{en:e.postScriptName||e.familyName+e.styleName},designer:{en:e.designer||" "},designerURL:{en:e.designerURL||" "},manufacturer:{en:e.manufacturer||" "},manufacturerURL:{en:e.manufacturerURL||" "},license:{en:e.license||" "},licenseURL:{en:e.licenseURL||" "},version:{en:e.version||"Version 0.1"},description:{en:e.description||" "},copyright:{en:e.copyright||" "},trademark:{en:e.trademark||" "}},this.unitsPerEm=e.unitsPerEm||1e3,this.ascender=e.ascender,this.descender=e.descender,this.createdTimestamp=e.createdTimestamp,this.tables={os2:{usWeightClass:e.weightClass||this.usWeightClasses.MEDIUM,usWidthClass:e.widthClass||this.usWidthClasses.MEDIUM,fsSelection:e.fsSelection||this.fsSelectionValues.REGULAR}}),this.supported=!0,this.glyphs=new Ie.GlyphSet(this,e.glyphs||[]),this.encoding=new ve(this),this.substitution=new It(this),this.tables=this.tables||{},Object.defineProperty(this,"hinting",{get:function(){return this._hinting?this._hinting:"truetype"===this.outlinesFormat?this._hinting=new zt(this):void 0}})}function Dn(e,t){const n=JSON.stringify(e);let o=256;for(let e in t){let r=parseInt(e);if(r&&!(r<256)){if(JSON.stringify(t[e])===n)return r;o<=r&&(o=r+1)}}return t[o]=e,o}function Cn(e,t,n){const o=Dn(t.name,n);return[{name:"tag_"+e,type:"TAG",value:t.tag},{name:"minValue_"+e,type:"FIXED",value:t.minValue<<16},{name:"defaultValue_"+e,type:"FIXED",value:t.defaultValue<<16},{name:"maxValue_"+e,type:"FIXED",value:t.maxValue<<16},{name:"flags_"+e,type:"USHORT",value:0},{name:"nameID_"+e,type:"USHORT",value:o}]}function Ln(e,t,n){const o={},r=new pe.Parser(e,t);return o.tag=r.parseTag(),o.minValue=r.parseFixed(),o.defaultValue=r.parseFixed(),o.maxValue=r.parseFixed(),r.skip("uShort",1),o.name=n[r.parseUShort()]||{},o}function In(e,t,n,o){const r=[{name:"nameID_"+e,type:"USHORT",value:Dn(t.name,o)},{name:"flags_"+e,type:"USHORT",value:0}];for(let o=0;o2)return;const n=this.font;let o=this._prepState;if(!o||o.ppem!==t){let e=this._fpgmState;if(!e){nn.prototype=tn,e=this._fpgmState=new nn("fpgm",n.tables.fpgm),e.funcs=[],e.font=n,exports.DEBUG&&(console.log("---EXEC FPGM---"),e.step=-1);try{At(e)}catch(e){return console.log("Hinting error in FPGM:"+e),void(this._errorState=3)}}nn.prototype=e,o=this._prepState=new nn("prep",n.tables.prep),o.ppem=t;const r=n.tables.cvt;if(r){const e=o.cvt=new Array(r.length),s=t/n.unitsPerEm;for(let t=0;t1))try{return Ft(e,o)}catch(e){return this._errorState<1&&(console.log("Hinting error:"+e),console.log("Note: further hinting errors are silenced")),void(this._errorState=1)}},Ft=function(e,t){const n=t.ppem/t.font.unitsPerEm,o=n;let r,s,a,i=e.components;if(nn.prototype=t,i){const l=t.font;s=[],r=[];for(let e=0;e1?"loop "+(e.loop-n)+": ":"")+"SHPIX[]",a,r),o.setRelative(i,i,r),o.touch(i)}e.loop=1},function(e){const t=e.stack,n=e.rp1,o=e.rp2;let r=e.loop;const s=e.z0[n],a=e.z1[o],i=e.fv,l=e.dpv,c=e.z2;for(;r--;){const u=t.pop(),p=c[u];exports.DEBUG&&console.log(e.step,(e.loop>1?"loop "+(e.loop-r)+": ":"")+"IP[]",u,n,"<->",o),i.interpolate(p,s,a,l),i.touch(p)}e.loop=1},yn.bind(void 0,0),yn.bind(void 0,1),function(e){const t=e.stack,n=e.rp0,o=e.z0[n];let r=e.loop;const s=e.fv,a=e.pv,i=e.z1;for(;r--;){const n=t.pop(),l=i[n];exports.DEBUG&&console.log(e.step,(e.loop>1?"loop "+(e.loop-r)+": ":"")+"ALIGNRP[]",n),s.setRelative(l,o,0,a),s.touch(l)}e.loop=1},function(e){exports.DEBUG&&console.log(e.step,"RTDG[]"),e.round=qt},vn.bind(void 0,0),vn.bind(void 0,1),function(e){const t=e.prog;let n=e.ip;const o=e.stack,r=t[++n];exports.DEBUG&&console.log(e.step,"NPUSHB[]",r);for(let e=0;en?1:0)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"GTEQ[]",n,o),t.push(o>=n?1:0)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"EQ[]",n,o),t.push(n===o?1:0)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"NEQ[]",n,o),t.push(n!==o?1:0)},function(e){const t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,"ODD[]",n),t.push(Math.trunc(n)%2?1:0)},function(e){const t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,"EVEN[]",n),t.push(Math.trunc(n)%2?0:1)},function(e){let t=e.stack.pop();exports.DEBUG&&console.log(e.step,"IF[]",t),t||(rn(e,!0),exports.DEBUG&&console.log(e.step,"EIF[]"))},function(e){exports.DEBUG&&console.log(e.step,"EIF[]")},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"AND[]",n,o),t.push(n&&o?1:0)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"OR[]",n,o),t.push(n||o?1:0)},function(e){const t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,"NOT[]",n),t.push(n?0:1)},xn.bind(void 0,1),function(e){const t=e.stack.pop();exports.DEBUG&&console.log(e.step,"SDB[]",t),e.deltaBase=t},function(e){const t=e.stack.pop();exports.DEBUG&&console.log(e.step,"SDS[]",t),e.deltaShift=Math.pow(.5,t)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"ADD[]",n,o),t.push(o+n)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"SUB[]",n,o),t.push(o-n)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"DIV[]",n,o),t.push(64*o/n)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"MUL[]",n,o),t.push(o*n/64)},function(e){const t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,"ABS[]",n),t.push(Math.abs(n))},function(e){const t=e.stack;let n=t.pop();exports.DEBUG&&console.log(e.step,"NEG[]",n),t.push(-n)},function(e){const t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,"FLOOR[]",n),t.push(64*Math.floor(n/64))},function(e){const t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,"CEILING[]",n),t.push(64*Math.ceil(n/64))},Un.bind(void 0,0),Un.bind(void 0,1),Un.bind(void 0,2),Un.bind(void 0,3),void 0,void 0,void 0,void 0,function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"WCVTF[]",n,o),e.cvt[o]=n*e.ppem/e.font.unitsPerEm},xn.bind(void 0,2),xn.bind(void 0,3),Tn.bind(void 0,1),Tn.bind(void 0,2),Tn.bind(void 0,3),function(e){let t,n=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,"SROUND[]",n),e.round=Yt,192&n){case 0:t=.5;break;case 64:t=1;break;case 128:t=2;break;default:throw new Error("invalid SROUND value")}switch(e.srPeriod=t,48&n){case 0:e.srPhase=0;break;case 16:e.srPhase=.25*t;break;case 32:e.srPhase=.5*t;break;case 48:e.srPhase=.75*t;break;default:throw new Error("invalid SROUND value")}n&=15,e.srThreshold=0===n?0:(n/8-.5)*t},function(e){let t,n=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,"S45ROUND[]",n),e.round=Yt,192&n){case 0:t=Math.sqrt(2)/2;break;case 64:t=Math.sqrt(2);break;case 128:t=2*Math.sqrt(2);break;default:throw new Error("invalid S45ROUND value")}switch(e.srPeriod=t,48&n){case 0:e.srPhase=0;break;case 16:e.srPhase=.25*t;break;case 32:e.srPhase=.5*t;break;case 48:e.srPhase=.75*t;break;default:throw new Error("invalid S45ROUND value")}n&=15,e.srThreshold=0===n?0:(n/8-.5)*t},void 0,void 0,function(e){exports.DEBUG&&console.log(e.step,"ROFF[]"),e.round=Wt},void 0,function(e){exports.DEBUG&&console.log(e.step,"RUTG[]"),e.round=Vt},function(e){exports.DEBUG&&console.log(e.step,"RDTG[]"),e.round=jt},pn,pn,void 0,void 0,void 0,void 0,void 0,function(e){const t=e.stack.pop();exports.DEBUG&&console.log(e.step,"SCANCTRL[]",t)},En.bind(void 0,0),En.bind(void 0,1),function(e){const t=e.stack,n=t.pop();let o=0;exports.DEBUG&&console.log(e.step,"GETINFO[]",n),1&n&&(o=35),32&n&&(o|=4096),t.push(o)},void 0,function(e){const t=e.stack,n=t.pop(),o=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,"ROLL[]"),t.push(o),t.push(n),t.push(r)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"MAX[]",n,o),t.push(Math.max(o,n))},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"MIN[]",n,o),t.push(Math.min(o,n))},function(e){const t=e.stack.pop();exports.DEBUG&&console.log(e.step,"SCANTYPE[]",t)},function(e){const t=e.stack.pop();let n=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,"INSTCTRL[]",t,n),t){case 1:return void(e.inhibitGridFit=!!n);case 2:return void(e.ignoreCvt=!!n);default:throw new Error("invalid INSTCTRL[] selector")}},void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,On.bind(void 0,1),On.bind(void 0,2),On.bind(void 0,3),On.bind(void 0,4),On.bind(void 0,5),On.bind(void 0,6),On.bind(void 0,7),On.bind(void 0,8),wn.bind(void 0,1),wn.bind(void 0,2),wn.bind(void 0,3),wn.bind(void 0,4),wn.bind(void 0,5),wn.bind(void 0,6),wn.bind(void 0,7),wn.bind(void 0,8),kn.bind(void 0,0,0,0,0,0),kn.bind(void 0,0,0,0,0,1),kn.bind(void 0,0,0,0,0,2),kn.bind(void 0,0,0,0,0,3),kn.bind(void 0,0,0,0,1,0),kn.bind(void 0,0,0,0,1,1),kn.bind(void 0,0,0,0,1,2),kn.bind(void 0,0,0,0,1,3),kn.bind(void 0,0,0,1,0,0),kn.bind(void 0,0,0,1,0,1),kn.bind(void 0,0,0,1,0,2),kn.bind(void 0,0,0,1,0,3),kn.bind(void 0,0,0,1,1,0),kn.bind(void 0,0,0,1,1,1),kn.bind(void 0,0,0,1,1,2),kn.bind(void 0,0,0,1,1,3),kn.bind(void 0,0,1,0,0,0),kn.bind(void 0,0,1,0,0,1),kn.bind(void 0,0,1,0,0,2),kn.bind(void 0,0,1,0,0,3),kn.bind(void 0,0,1,0,1,0),kn.bind(void 0,0,1,0,1,1),kn.bind(void 0,0,1,0,1,2),kn.bind(void 0,0,1,0,1,3),kn.bind(void 0,0,1,1,0,0),kn.bind(void 0,0,1,1,0,1),kn.bind(void 0,0,1,1,0,2),kn.bind(void 0,0,1,1,0,3),kn.bind(void 0,0,1,1,1,0),kn.bind(void 0,0,1,1,1,1),kn.bind(void 0,0,1,1,1,2),kn.bind(void 0,0,1,1,1,3),kn.bind(void 0,1,0,0,0,0),kn.bind(void 0,1,0,0,0,1),kn.bind(void 0,1,0,0,0,2),kn.bind(void 0,1,0,0,0,3),kn.bind(void 0,1,0,0,1,0),kn.bind(void 0,1,0,0,1,1),kn.bind(void 0,1,0,0,1,2),kn.bind(void 0,1,0,0,1,3),kn.bind(void 0,1,0,1,0,0),kn.bind(void 0,1,0,1,0,1),kn.bind(void 0,1,0,1,0,2),kn.bind(void 0,1,0,1,0,3),kn.bind(void 0,1,0,1,1,0),kn.bind(void 0,1,0,1,1,1),kn.bind(void 0,1,0,1,1,2),kn.bind(void 0,1,0,1,1,3),kn.bind(void 0,1,1,0,0,0),kn.bind(void 0,1,1,0,0,1),kn.bind(void 0,1,1,0,0,2),kn.bind(void 0,1,1,0,0,3),kn.bind(void 0,1,1,0,1,0),kn.bind(void 0,1,1,0,1,1),kn.bind(void 0,1,1,0,1,2),kn.bind(void 0,1,1,0,1,3),kn.bind(void 0,1,1,1,0,0),kn.bind(void 0,1,1,1,0,1),kn.bind(void 0,1,1,1,0,2),kn.bind(void 0,1,1,1,0,3),kn.bind(void 0,1,1,1,1,0),kn.bind(void 0,1,1,1,1,1),kn.bind(void 0,1,1,1,1,2),kn.bind(void 0,1,1,1,1,3)],Rn.prototype.hasChar=function(e){return null!==this.encoding.charToGlyphIndex(e)},Rn.prototype.charToGlyphIndex=function(e){return this.encoding.charToGlyphIndex(e)},Rn.prototype.charToGlyph=function(e){const t=this.charToGlyphIndex(e);let n=this.glyphs.get(t);return n||(n=this.glyphs.get(0)),n},Rn.prototype.stringToGlyphs=function(e,t){t=t||this.defaultRenderOptions;const n=[];for(let t=0;t>1;e1&&console.warn("Only the first kern subtable is supported."),e.skip("uLong");const n=255&e.parseUShort();if(e.skip("uShort"),0===n){const n=e.parseUShort();e.skip("uShort",3);for(let o=0;o{const t=jn.loadSync(e);Qn.font=t,Qn.ascender=t.ascender,Qn.descender=t.descender}};const Kn=$n.options,Jn=function(e,t){return Math.round(e+Math.random()*(t-e))};const eo=function(e,t){return{text:(e+t).toString(),equation:e+"+"+t}},to=function(e,t){return{text:(e-t).toString(),equation:e+"-"+t}};function no(e,t,n){return 6*(n=(n+1)%1)<1?e+(t-e)*n*6:2*n<1?t:3*n<2?e+(t-e)*(2/3-n)*6:e}var oo={int:Jn,greyColor:function(e,t){const n=Jn(e=e||1,t=t||9).toString(16);return`#${n}${n}${n}`},captchaText:function(e){"number"==typeof e&&(e={size:e});const t=(e=e||{}).size||4,n=e.ignoreChars||"";let o=-1,r="",s=e.charPreset||Kn.charPreset;n&&(s=function(e,t){return e.split("").filter(e=>-1===t.indexOf(e))}(s,n));const a=s.length-1;for(;++o>16,o=t>>8&255,r=255&t,s=Math.max(n,o,r),a=Math.min(n,o,r);return(s+a)/510}(e):1;let r,s;o>=.5?(r=Math.round(100*o)-45,s=Math.round(100*o)-25):(r=Math.round(100*o)+25,s=Math.round(100*o)+45);const a=Jn(r,s)/100,i=a<.5?a*(a+n):a+n-a*n,l=2*a-i,c=Math.floor(255*no(l,i,t+1/3)),u=Math.floor(255*no(l,i,t));return"#"+(Math.floor(255*no(l,i,t-1/3))|u<<8|c<<16|1<<24).toString(16).slice(1)}};const ro=$n.options,so=function(e,t){e=e||oo.captchaText();const n=(t=Object.assign({},ro,t)).width,o=t.height,r=t.background||t.backgroundColor;r&&(t.color=!0);const s=r?``:"",a=[].concat(function(e,t,n){const o=n.color,r=[],s=n.inverse?7:1,a=n.inverse?15:9;let i=-1;for(;++i`)}return r}(n,o,t)).concat(function(e,t,n,o,r){const s=e.length,a=(t-2)/(s+1),i=o.inverse?10:0,l=o.inverse?14:4;let u=-1;const p=[],h=r||o.color?oo.color(o.background):oo.greyColor(i,l);for(;++u`)}return p}(e,n,o,t)).sort(()=>Math.random()-.5).join("");return`${``};var ao=so,io=oo.captchaText,lo=function(e){const t=e.text||oo.captchaText(e);return{text:t,data:so(t,e)}},co=function(e){const t=oo.mathExpr(e.mathMin,e.mathMax,e.mathOperator);return{text:t.text,data:so(t.equation,e)}},uo=ro,po=$n.loadFont;ao.randomText=io,ao.create=lo,ao.createMathExpr=co,ao.options=uo,ao.loadFont=po;var ho=ao;const fo=Object.prototype.toString;function go(e){return"[object Object]"===fo.call(e)}function mo(){"development"===process.env.NODE_ENV&&console.log(...arguments)}const yo=async function(){};function vo(e){return yo.constructor===e.constructor?async function(){const t=await e.apply(this,arguments);return go(t)&&(t.msg&&(t.message=t.msg,t.errMsg=t.msg),0===t.code?t.errCode=t.code:t.errCode=s[t.code]||t.code),t}:function(){const t=e.apply(this,arguments);return go(t)&&(t.msg&&(t.message=t.msg,t.errMsg=t.msg),0===t.code?t.errCode=t.code:t.errCode=s[t.code]||t.code),t}}const bo=uniCloud.database().collection("opendb-verify-codes");class So{async setVerifyCode({deviceId:e,code:t,expiresDate:n,scene:o}){if(!e)return{code:10101,msg:"deviceId不可为空"};if(!t)return{code:10102,msg:"验证码不可为空"};n||(n=180);const r=Date.now(),s={deviceId:e,scene:o,code:t.toLocaleLowerCase(),state:0,ip:__ctx__.CLIENTIP,created_date:r,expired_date:r+1e3*n};return mo("addRes",await bo.add(s)),{code:0,deviceId:e}}async verifyCode({deviceId:e,code:t,scene:n}){if(!e)return{code:10101,msg:"deviceId不可为空"};if(!t)return{code:10102,msg:"验证码不可为空"};const o=Date.now(),r={deviceId:e,scene:n,code:t.toLocaleLowerCase(),state:0},s=await bo.where(r).orderBy("created_date","desc").limit(1).get();if(mo("verifyRecord:",s),s&&s.data&&s.data.length>0){const e=s.data[0];if(e.expired_date{e.scene&&delete e.scene,this.pluginConfig.scene[n]=Object.assign({},t,e[n])})}}}{constructor(){super(),this.DEVICEID2opts={}}mergeConfig(e){const t=go(this.pluginConfig.scene)?this.pluginConfig.scene[e.scene]:e.scene;return Object.assign({},go(t)?t:this.pluginConfig,e)}async create(e={}){if(!e.scene)throw new Error("scene验证码场景不可为空");e=this.mergeConfig(e);let{scene:t,expiresDate:n,deviceId:o,...r}=e;if(o=o||__ctx__.DEVICEID,!o)throw new Error("deviceId不可为空");const s=new So;try{const{text:a,base64:i}=function(e={}){const{uniPlatform:t=""}=e;let n;n=e.mathExpr?ho.createMathExpr(e):ho.create(e);let o="data:image/svg+xml;utf8,"+n.data.replace(/#/g,"%23");return(!t||"string"==typeof t&&-1===t.indexOf("mp-"))&&(o=o.replace(/"/g,"'").replace(//g,"%3E")),{text:n.text,base64:o}}(r),l=await s.setVerifyCode({deviceId:o,code:a,expiresDate:n,scene:t});return l.code>0?{...l,code:10001}:(this.DEVICEID2opts[o]=e,{code:0,msg:"验证码获取成功",captchaBase64:i})}catch(e){return{code:10001,msg:"验证码生成失败:"+e.message}}}async verify({deviceId:e,captcha:t,scene:n}){if(!(e=e||__ctx__.DEVICEID))throw new Error("deviceId不可为空");if(!n)throw new Error("scene验证码场景不可为空");const o=new So;try{const r=await o.verifyCode({deviceId:e,code:t,scene:n});return r.code>0?r:{code:0,msg:"验证码通过"}}catch(e){return{code:10002,msg:"验证码校验失败:"+e.message}}}async refresh(e={}){let{scene:t,expiresDate:n,deviceId:o,...r}=e;if(o=o||__ctx__.DEVICEID,!o)throw new Error("deviceId不可为空");if(!t)throw new Error("scene验证码场景不可为空");const s=await bo.where({deviceId:o,scene:t}).orderBy("created_date","desc").limit(1).get();if(s&&s.data&&s.data.length>0){const e=s.data[0];await bo.doc(e._id).update({state:2}),Object.keys(r).length>0&&(this.DEVICEID2opts[o]=Object.assign({},this.DEVICEID2opts[o],r));let a={};try{a=await this.create(Object.assign({},this.DEVICEID2opts[o],{deviceId:o,scene:t,expiresDate:n}))}catch(e){return{code:50403,msg:e.message}}return a.code>0?{...a,code:50403}:{code:0,msg:"验证码刷新成功",captchaBase64:a.captchaBase64}}return{code:10003,msg:`验证码刷新失败:无此设备在 ${t} 场景信息,请重新获取`}}}const To=new So;Object.keys(To).forEach(e=>{Uo.prototype[e]=vo(To[e])});const Eo=new Uo,Oo=new Proxy(Eo,{get(e,t){if(t in e)return"function"==typeof e[t]?vo(e[t]).bind(Oo):e[t]}});module.exports=Oo;
diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-captcha/node_modules/uni-config-center/index.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-captcha/node_modules/uni-config-center/index.js
new file mode 100644
index 0000000000000000000000000000000000000000..e14fb3b0a213443d5c51cb3fcb763d322c21c97f
--- /dev/null
+++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-captcha/node_modules/uni-config-center/index.js
@@ -0,0 +1 @@
+"use strict";var t=require("fs"),r=require("path");function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=e(t),o=e(r),i="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var u=function(t){var r={exports:{}};return t(r,r.exports),r.exports}((function(t,r){var e="__lodash_hash_undefined__",n=9007199254740991,o="[object Arguments]",u="[object Function]",c="[object Object]",a=/^\[object .+?Constructor\]$/,f=/^(?:0|[1-9]\d*)$/,s={};s["[object Float32Array]"]=s["[object Float64Array]"]=s["[object Int8Array]"]=s["[object Int16Array]"]=s["[object Int32Array]"]=s["[object Uint8Array]"]=s["[object Uint8ClampedArray]"]=s["[object Uint16Array]"]=s["[object Uint32Array]"]=!0,s[o]=s["[object Array]"]=s["[object ArrayBuffer]"]=s["[object Boolean]"]=s["[object DataView]"]=s["[object Date]"]=s["[object Error]"]=s[u]=s["[object Map]"]=s["[object Number]"]=s[c]=s["[object RegExp]"]=s["[object Set]"]=s["[object String]"]=s["[object WeakMap]"]=!1;var l="object"==typeof i&&i&&i.Object===Object&&i,h="object"==typeof self&&self&&self.Object===Object&&self,p=l||h||Function("return this")(),_=r&&!r.nodeType&&r,v=_&&t&&!t.nodeType&&t,d=v&&v.exports===_,y=d&&l.process,g=function(){try{var t=v&&v.require&&v.require("util").types;return t||y&&y.binding&&y.binding("util")}catch(t){}}(),b=g&&g.isTypedArray;function j(t,r,e){switch(e.length){case 0:return t.call(r);case 1:return t.call(r,e[0]);case 2:return t.call(r,e[0],e[1]);case 3:return t.call(r,e[0],e[1],e[2])}return t.apply(r,e)}var w,O,m,A=Array.prototype,z=Function.prototype,M=Object.prototype,x=p["__core-js_shared__"],C=z.toString,F=M.hasOwnProperty,U=(w=/[^.]+$/.exec(x&&x.keys&&x.keys.IE_PROTO||""))?"Symbol(src)_1."+w:"",S=M.toString,I=C.call(Object),P=RegExp("^"+C.call(F).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),T=d?p.Buffer:void 0,q=p.Symbol,E=p.Uint8Array,$=T?T.allocUnsafe:void 0,D=(O=Object.getPrototypeOf,m=Object,function(t){return O(m(t))}),k=Object.create,B=M.propertyIsEnumerable,N=A.splice,L=q?q.toStringTag:void 0,R=function(){try{var t=_t(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),G=T?T.isBuffer:void 0,V=Math.max,W=Date.now,H=_t(p,"Map"),J=_t(Object,"create"),K=function(){function t(){}return function(r){if(!Mt(r))return{};if(k)return k(r);t.prototype=r;var e=new t;return t.prototype=void 0,e}}();function Q(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r-1},X.prototype.set=function(t,r){var e=this.__data__,n=nt(e,t);return n<0?(++this.size,e.push([t,r])):e[n][1]=r,this},Y.prototype.clear=function(){this.size=0,this.__data__={hash:new Q,map:new(H||X),string:new Q}},Y.prototype.delete=function(t){var r=pt(this,t).delete(t);return this.size-=r?1:0,r},Y.prototype.get=function(t){return pt(this,t).get(t)},Y.prototype.has=function(t){return pt(this,t).has(t)},Y.prototype.set=function(t,r){var e=pt(this,t),n=e.size;return e.set(t,r),this.size+=e.size==n?0:1,this},Z.prototype.clear=function(){this.__data__=new X,this.size=0},Z.prototype.delete=function(t){var r=this.__data__,e=r.delete(t);return this.size=r.size,e},Z.prototype.get=function(t){return this.__data__.get(t)},Z.prototype.has=function(t){return this.__data__.has(t)},Z.prototype.set=function(t,r){var e=this.__data__;if(e instanceof X){var n=e.__data__;if(!H||n.length<199)return n.push([t,r]),this.size=++e.size,this;e=this.__data__=new Y(n)}return e.set(t,r),this.size=e.size,this};var it,ut=function(t,r,e){for(var n=-1,o=Object(t),i=e(t),u=i.length;u--;){var c=i[it?u:++n];if(!1===r(o[c],c,o))break}return t};function ct(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":L&&L in Object(t)?function(t){var r=F.call(t,L),e=t[L];try{t[L]=void 0;var n=!0}catch(t){}var o=S.call(t);n&&(r?t[L]=e:delete t[L]);return o}(t):function(t){return S.call(t)}(t)}function at(t){return xt(t)&&ct(t)==o}function ft(t){return!(!Mt(t)||function(t){return!!U&&U in t}(t))&&(At(t)?P:a).test(function(t){if(null!=t){try{return C.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function st(t){if(!Mt(t))return function(t){var r=[];if(null!=t)for(var e in Object(t))r.push(e);return r}(t);var r=dt(t),e=[];for(var n in t)("constructor"!=n||!r&&F.call(t,n))&&e.push(n);return e}function lt(t,r,e,n,o){t!==r&&ut(r,(function(i,u){if(o||(o=new Z),Mt(i))!function(t,r,e,n,o,i,u){var a=yt(t,e),f=yt(r,e),s=u.get(f);if(s)return void rt(t,e,s);var l=i?i(a,f,e+"",t,r,u):void 0,h=void 0===l;if(h){var p=wt(f),_=!p&&mt(f),v=!p&&!_&&Ct(f);l=f,p||_||v?wt(a)?l=a:xt(j=a)&&Ot(j)?l=function(t,r){var e=-1,n=t.length;r||(r=Array(n));for(;++e-1&&t%1==0&&t0){if(++r>=800)return arguments[0]}else r=0;return t.apply(void 0,arguments)}}(R?function(t,r){return R(t,"toString",{configurable:!0,enumerable:!1,value:(e=r,function(){return e}),writable:!0});var e}:It);function bt(t,r){return t===r||t!=t&&r!=r}var jt=at(function(){return arguments}())?at:function(t){return xt(t)&&F.call(t,"callee")&&!B.call(t,"callee")},wt=Array.isArray;function Ot(t){return null!=t&&zt(t.length)&&!At(t)}var mt=G||function(){return!1};function At(t){if(!Mt(t))return!1;var r=ct(t);return r==u||"[object GeneratorFunction]"==r||"[object AsyncFunction]"==r||"[object Proxy]"==r}function zt(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=n}function Mt(t){var r=typeof t;return null!=t&&("object"==r||"function"==r)}function xt(t){return null!=t&&"object"==typeof t}var Ct=b?function(t){return function(r){return t(r)}}(b):function(t){return xt(t)&&zt(t.length)&&!!s[ct(t)]};function Ft(t){return Ot(t)?tt(t,!0):st(t)}var Ut,St=(Ut=function(t,r,e){lt(t,r,e)},ht((function(t,r){var e=-1,n=r.length,o=n>1?r[n-1]:void 0,i=n>2?r[2]:void 0;for(o=Ut.length>3&&"function"==typeof o?(n--,o):void 0,i&&function(t,r,e){if(!Mt(e))return!1;var n=typeof r;return!!("number"==n?Ot(e)&&vt(r,e.length):"string"==n&&r in e)&&bt(e[r],t)}(r[0],r[1],i)&&(o=n<3?void 0:o,n=1),t=Object(t);++ec.call(t,r);class f{constructor({pluginId:t,defaultConfig:r={},customMerge:e,root:n}){this.pluginId=t,this.defaultConfig=r,this.pluginConfigPath=o.default.resolve(n||__dirname,t),this.customMerge=e,this._config=void 0}resolve(t){return o.default.resolve(this.pluginConfigPath,t)}hasFile(t){return n.default.existsSync(this.resolve(t))}requireFile(t){try{return require(this.resolve(t))}catch(t){if("MODULE_NOT_FOUND"===t.code)return;throw t}}_getUserConfig(){return this.requireFile("config.json")}config(t,r){this._config||(this._config=(this.customMerge||u)(this.defaultConfig,this._getUserConfig()));let e=this._config;return t?function(t,r,e){if("number"==typeof r)return t[r];if("symbol"==typeof r)return a(t,r)?t[r]:e;const n="string"!=typeof(o=r)?o:o.split(".").reduce(((t,r)=>(r.split(/\[([^}]+)\]/g).forEach((r=>r&&t.push(r))),t)),[]);var o;let i=t;for(let t=0;t-1},X.prototype.set=function(t,r){var e=this.__data__,n=nt(e,t);return n<0?(++this.size,e.push([t,r])):e[n][1]=r,this},Y.prototype.clear=function(){this.size=0,this.__data__={hash:new Q,map:new(H||X),string:new Q}},Y.prototype.delete=function(t){var r=pt(this,t).delete(t);return this.size-=r?1:0,r},Y.prototype.get=function(t){return pt(this,t).get(t)},Y.prototype.has=function(t){return pt(this,t).has(t)},Y.prototype.set=function(t,r){var e=pt(this,t),n=e.size;return e.set(t,r),this.size+=e.size==n?0:1,this},Z.prototype.clear=function(){this.__data__=new X,this.size=0},Z.prototype.delete=function(t){var r=this.__data__,e=r.delete(t);return this.size=r.size,e},Z.prototype.get=function(t){return this.__data__.get(t)},Z.prototype.has=function(t){return this.__data__.has(t)},Z.prototype.set=function(t,r){var e=this.__data__;if(e instanceof X){var n=e.__data__;if(!H||n.length<199)return n.push([t,r]),this.size=++e.size,this;e=this.__data__=new Y(n)}return e.set(t,r),this.size=e.size,this};var it,ut=function(t,r,e){for(var n=-1,o=Object(t),i=e(t),u=i.length;u--;){var c=i[it?u:++n];if(!1===r(o[c],c,o))break}return t};function ct(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":L&&L in Object(t)?function(t){var r=F.call(t,L),e=t[L];try{t[L]=void 0;var n=!0}catch(t){}var o=S.call(t);n&&(r?t[L]=e:delete t[L]);return o}(t):function(t){return S.call(t)}(t)}function at(t){return xt(t)&&ct(t)==o}function ft(t){return!(!Mt(t)||function(t){return!!U&&U in t}(t))&&(At(t)?P:a).test(function(t){if(null!=t){try{return C.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function st(t){if(!Mt(t))return function(t){var r=[];if(null!=t)for(var e in Object(t))r.push(e);return r}(t);var r=dt(t),e=[];for(var n in t)("constructor"!=n||!r&&F.call(t,n))&&e.push(n);return e}function lt(t,r,e,n,o){t!==r&&ut(r,(function(i,u){if(o||(o=new Z),Mt(i))!function(t,r,e,n,o,i,u){var a=yt(t,e),f=yt(r,e),s=u.get(f);if(s)return void rt(t,e,s);var l=i?i(a,f,e+"",t,r,u):void 0,h=void 0===l;if(h){var p=wt(f),_=!p&&mt(f),v=!p&&!_&&Ct(f);l=f,p||_||v?wt(a)?l=a:xt(j=a)&&Ot(j)?l=function(t,r){var e=-1,n=t.length;r||(r=Array(n));for(;++e-1&&t%1==0&&t0){if(++r>=800)return arguments[0]}else r=0;return t.apply(void 0,arguments)}}(R?function(t,r){return R(t,"toString",{configurable:!0,enumerable:!1,value:(e=r,function(){return e}),writable:!0});var e}:It);function bt(t,r){return t===r||t!=t&&r!=r}var jt=at(function(){return arguments}())?at:function(t){return xt(t)&&F.call(t,"callee")&&!B.call(t,"callee")},wt=Array.isArray;function Ot(t){return null!=t&&zt(t.length)&&!At(t)}var mt=G||function(){return!1};function At(t){if(!Mt(t))return!1;var r=ct(t);return r==u||"[object GeneratorFunction]"==r||"[object AsyncFunction]"==r||"[object Proxy]"==r}function zt(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=n}function Mt(t){var r=typeof t;return null!=t&&("object"==r||"function"==r)}function xt(t){return null!=t&&"object"==typeof t}var Ct=b?function(t){return function(r){return t(r)}}(b):function(t){return xt(t)&&zt(t.length)&&!!s[ct(t)]};function Ft(t){return Ot(t)?tt(t,!0):st(t)}var Ut,St=(Ut=function(t,r,e){lt(t,r,e)},ht((function(t,r){var e=-1,n=r.length,o=n>1?r[n-1]:void 0,i=n>2?r[2]:void 0;for(o=Ut.length>3&&"function"==typeof o?(n--,o):void 0,i&&function(t,r,e){if(!Mt(e))return!1;var n=typeof r;return!!("number"==n?Ot(e)&&vt(r,e.length):"string"==n&&r in e)&&bt(e[r],t)}(r[0],r[1],i)&&(o=n<3?void 0:o,n=1),t=Object(t);++ec.call(t,r);class f{constructor({pluginId:t,defaultConfig:r={},customMerge:e,root:n}){this.pluginId=t,this.defaultConfig=r,this.pluginConfigPath=o.default.resolve(n||__dirname,t),this.customMerge=e,this._config=void 0}resolve(t){return o.default.resolve(this.pluginConfigPath,t)}hasFile(t){return n.default.existsSync(this.resolve(t))}requireFile(t){try{return require(this.resolve(t))}catch(t){if("MODULE_NOT_FOUND"===t.code)return;throw t}}_getUserConfig(){return this.requireFile("config.json")}config(t,r){this._config||(this._config=(this.customMerge||u)(this.defaultConfig,this._getUserConfig()));let e=this._config;return t?function(t,r,e){if("number"==typeof r)return t[r];if("symbol"==typeof r)return a(t,r)?t[r]:e;const n="string"!=typeof(o=r)?o:o.split(".").reduce(((t,r)=>(r.split(/\[([^}]+)\]/g).forEach((r=>r&&t.push(r))),t)),[]);var o;let i=t;for(let t=0;tparseInt(e)):void 0}function o(e,t){const n=r(e),i=r(t);return n?i?function(e,t){const n=Math.max(e.length,t.length);for(let i=0;ir)return 1;if(ne)throw new Error("Config error, tokenExpiresThreshold should be less than tokenExpiresIn")}get customToken(){return this.uniId.interceptorMap.get("customToken")}isTokenInDb(e){return o(e,"1.0.10")>=0}async getUserRecord(){if(this.userRecord)return this.userRecord;const e=await C.doc(this.uid).get();if(this.userRecord=e.data[0],!this.userRecord)throw{errCode:n.ACCOUNT_NOT_EXISTS};switch(this.userRecord.status){case void 0:case 0:break;case 1:throw{errCode:n.ACCOUNT_BANNED};case 2:throw{errCode:n.ACCOUNT_AUDITING};case 3:throw{errCode:n.ACCOUNT_AUDIT_FAILED};case 4:throw{errCode:n.ACCOUNT_CLOSED}}if(this.oldTokenPayload){if(this.isTokenInDb(this.oldTokenPayload.uniIdVersion)){if(-1===(this.userRecord.token||[]).indexOf(this.oldToken))throw{errCode:n.CHECK_TOKEN_FAILED}}if(this.userRecord.valid_token_date&&this.userRecord.valid_token_date>1e3*this.oldTokenPayload.iat)throw{errCode:n.TOKEN_EXPIRED}}return this.userRecord}async updateUserRecord(e){await C.doc(this.uid).update(e)}async getUserPermission(){if(this.userPermission)return this.userPermission;const e=(await this.getUserRecord()).role||[];if(0===e.length)return this.userPermission={role:[],permission:[]},this.userPermission;if(e.includes("admin"))return this.userPermission={role:["admin"],permission:[]},this.userPermission;const t=await m.where({role_id:_.in(e)}).get(),n=(i=t.data.reduce((e,t)=>(t.permission&&e.push(...t.permission),e),[]),Array.from(new Set(i)));var i;return this.userPermission={role:e,permission:n},this.userPermission}async _createToken({uid:e,role:t,permission:i}={}){if(!t||!i){const e=await this.getUserPermission();t=e.role,i=e.permission}let r={uid:e,role:t,permission:i};if(this.uniId.interceptorMap.has("customToken")){const n=this.uniId.interceptorMap.get("customToken");if("function"!=typeof n)throw new Error("Invalid custom token file");r=await n({uid:e,role:t,permission:i})}const o=Date.now(),{tokenSecret:s,tokenExpiresIn:c}=this.config,a=g({...r,uniIdVersion:"1.0.13"},s,{expiresIn:c}),u=await this.getUserRecord(),d=(u.token||[]).filter(e=>{try{const t=this._checkToken(e);if(u.valid_token_date&&u.valid_token_date>1e3*t.iat)return!1}catch(e){if(e.errCode===n.TOKEN_EXPIRED)return!1}return!0});return d.push(a),await this.updateUserRecord({last_login_ip:this.clientInfo.clientIP,last_login_date:o,token:d}),{token:a,tokenExpired:o+1e3*c}}async createToken({uid:e,role:t,permission:i}={}){if(!e)throw{errCode:n.PARAM_REQUIRED,errMsgValue:{param:"uid"}};this.uid=e;const{token:r,tokenExpired:o}=await this._createToken({uid:e,role:t,permission:i});return{errCode:0,token:r,tokenExpired:o}}async refreshToken({token:e}={}){if(!e)throw{errCode:n.PARAM_REQUIRED,errMsgValue:{param:"token"}};this.oldToken=e;const t=this._checkToken(e);this.uid=t.uid,this.oldTokenPayload=t;const{uid:i}=t,{role:r,permission:o}=await this.getUserPermission(),{token:s,tokenExpired:c}=await this._createToken({uid:i,role:r,permission:o});return{errCode:0,token:s,tokenExpired:c}}_checkToken(e){const{tokenSecret:t}=this.config;let i;try{i=k(e,t)}catch(e){if("TokenExpiredError"===e.name)throw{errCode:n.TOKEN_EXPIRED};throw{errCode:n.CHECK_TOKEN_FAILED}}return i}async checkToken(e,{autoRefresh:t=!0}={}){if(!e)throw{errCode:n.PARAM_REQUIRED,errMsgValue:{param:"token"}};this.oldToken=e;const i=this._checkToken(e);this.uid=i.uid,this.oldTokenPayload=i;const{tokenExpiresThreshold:r}=this.config,{uid:o,role:s,permission:c}=i,a={role:s,permission:c};if(!s&&!c){const{role:e,permission:t}=await this.getUserPermission();a.role=e,a.permission=t}if(!r||!t){const e={code:0,errCode:0,...i,...a};return delete e.uniIdVersion,e}const u=Date.now();let d={};1e3*i.exp-u<1e3*r&&(d=await this._createToken({uid:o}));const l={code:0,errCode:0,...i,...a,...d};return delete l.uniIdVersion,l}}var E=Object.freeze({__proto__:null,checkToken:async function(e,{autoRefresh:t=!0}={}){return new T({uniId:this}).checkToken(e,{autoRefresh:t})},createToken:async function({uid:e,role:t,permission:n}={}){return new T({uniId:this}).createToken({uid:e,role:t,permission:n})},refreshToken:async function({token:e}={}){return new T({uniId:this}).refreshToken({token:e})}});const w=require("uni-config-center")({pluginId:"uni-id"});class A{constructor({context:e,clientInfo:t,config:n}={}){this._clientInfo=e?function(e){return{appId:e.APPID,platform:e.PLATFORM,locale:e.LOCALE,clientIP:e.CLIENTIP,deviceId:e.DEVICEID}}(e):t,this.config=n||this._getOriginConfig(),this.interceptorMap=new Map,w.hasFile("custom-token.js")&&this.setInterceptor("customToken",require(w.resolve("custom-token.js"))),this._i18n=uniCloud.initI18n({locale:this._clientInfo.locale,fallbackLocale:"zh-Hans",messages:d})}setInterceptor(e,t){this.interceptorMap.set(e,t)}_t(...e){return this._i18n.t(...e)}_parseOriginConfig(e){return Array.isArray(e)?e:e[0]?Object.values(e):e}_getOriginConfig(){if(w.hasFile("config.json")){let e;try{e=w.config()}catch(e){throw new Error("Invalid uni-id config file\n"+e.message)}return this._parseOriginConfig(e)}try{return this._parseOriginConfig(require("uni-id/config.json"))}catch(e){throw new Error("Invalid uni-id config file")}}_getAppConfig(){const e=this._getOriginConfig();return Array.isArray(e)?e.find(e=>e.dcloudAppid===this._clientInfo.appId)||e.find(e=>e.isDefaultConfig):e}_getPlatformConfig(){const e=this._getAppConfig();if(!e)throw new Error(`Config for current app (${this._clientInfo.appId}) was not found, please check your config file or client appId`);let t;switch("app-plus"===this._clientInfo.platform&&(this._clientInfo.platform="app"),"h5"===this._clientInfo.platform&&(this._clientInfo.platform="web"),this._clientInfo.platform){case"web":t="h5";break;case"app":t="app-plus"}const n=[{tokenExpiresIn:7200,tokenExpiresThreshold:1200,passwordErrorLimit:6,passwordErrorRetryTime:3600},e];t&&e[t]&&n.push(e[t]),n.push(e[this._clientInfo.platform]);const i=Object.assign(...n);return["tokenSecret","tokenExpiresIn"].forEach(e=>{if(!i||!i[e])throw new Error(`Config parameter missing, ${e} is required`)}),i}_getConfig(){return this._getPlatformConfig()}}for(const e in E)A.prototype[e]=E[e];function y(e){const t=new A(e);return new Proxy(t,{get(e,t){if(t in e&&0!==t.indexOf("_")){if("function"==typeof e[t])return(n=e[t],function(){let e;try{e=n.apply(this,arguments)}catch(e){if(a(e))return c.call(this,e),e;throw e}return i(e)?e.then(e=>(a(e)&&c.call(this,e),e),e=>{if(a(e))return c.call(this,e),e;throw e}):(a(e)&&c.call(this,e),e)}).bind(e);if("context"!==t&&"config"!==t)return e[t]}var n}})}A.prototype.createInstance=y;const x={createInstance:y};module.exports=x;
diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-id-common/node_modules/uni-config-center/index.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-id-common/node_modules/uni-config-center/index.js
new file mode 100644
index 0000000000000000000000000000000000000000..e14fb3b0a213443d5c51cb3fcb763d322c21c97f
--- /dev/null
+++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-id-common/node_modules/uni-config-center/index.js
@@ -0,0 +1 @@
+"use strict";var t=require("fs"),r=require("path");function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=e(t),o=e(r),i="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var u=function(t){var r={exports:{}};return t(r,r.exports),r.exports}((function(t,r){var e="__lodash_hash_undefined__",n=9007199254740991,o="[object Arguments]",u="[object Function]",c="[object Object]",a=/^\[object .+?Constructor\]$/,f=/^(?:0|[1-9]\d*)$/,s={};s["[object Float32Array]"]=s["[object Float64Array]"]=s["[object Int8Array]"]=s["[object Int16Array]"]=s["[object Int32Array]"]=s["[object Uint8Array]"]=s["[object Uint8ClampedArray]"]=s["[object Uint16Array]"]=s["[object Uint32Array]"]=!0,s[o]=s["[object Array]"]=s["[object ArrayBuffer]"]=s["[object Boolean]"]=s["[object DataView]"]=s["[object Date]"]=s["[object Error]"]=s[u]=s["[object Map]"]=s["[object Number]"]=s[c]=s["[object RegExp]"]=s["[object Set]"]=s["[object String]"]=s["[object WeakMap]"]=!1;var l="object"==typeof i&&i&&i.Object===Object&&i,h="object"==typeof self&&self&&self.Object===Object&&self,p=l||h||Function("return this")(),_=r&&!r.nodeType&&r,v=_&&t&&!t.nodeType&&t,d=v&&v.exports===_,y=d&&l.process,g=function(){try{var t=v&&v.require&&v.require("util").types;return t||y&&y.binding&&y.binding("util")}catch(t){}}(),b=g&&g.isTypedArray;function j(t,r,e){switch(e.length){case 0:return t.call(r);case 1:return t.call(r,e[0]);case 2:return t.call(r,e[0],e[1]);case 3:return t.call(r,e[0],e[1],e[2])}return t.apply(r,e)}var w,O,m,A=Array.prototype,z=Function.prototype,M=Object.prototype,x=p["__core-js_shared__"],C=z.toString,F=M.hasOwnProperty,U=(w=/[^.]+$/.exec(x&&x.keys&&x.keys.IE_PROTO||""))?"Symbol(src)_1."+w:"",S=M.toString,I=C.call(Object),P=RegExp("^"+C.call(F).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),T=d?p.Buffer:void 0,q=p.Symbol,E=p.Uint8Array,$=T?T.allocUnsafe:void 0,D=(O=Object.getPrototypeOf,m=Object,function(t){return O(m(t))}),k=Object.create,B=M.propertyIsEnumerable,N=A.splice,L=q?q.toStringTag:void 0,R=function(){try{var t=_t(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),G=T?T.isBuffer:void 0,V=Math.max,W=Date.now,H=_t(p,"Map"),J=_t(Object,"create"),K=function(){function t(){}return function(r){if(!Mt(r))return{};if(k)return k(r);t.prototype=r;var e=new t;return t.prototype=void 0,e}}();function Q(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r-1},X.prototype.set=function(t,r){var e=this.__data__,n=nt(e,t);return n<0?(++this.size,e.push([t,r])):e[n][1]=r,this},Y.prototype.clear=function(){this.size=0,this.__data__={hash:new Q,map:new(H||X),string:new Q}},Y.prototype.delete=function(t){var r=pt(this,t).delete(t);return this.size-=r?1:0,r},Y.prototype.get=function(t){return pt(this,t).get(t)},Y.prototype.has=function(t){return pt(this,t).has(t)},Y.prototype.set=function(t,r){var e=pt(this,t),n=e.size;return e.set(t,r),this.size+=e.size==n?0:1,this},Z.prototype.clear=function(){this.__data__=new X,this.size=0},Z.prototype.delete=function(t){var r=this.__data__,e=r.delete(t);return this.size=r.size,e},Z.prototype.get=function(t){return this.__data__.get(t)},Z.prototype.has=function(t){return this.__data__.has(t)},Z.prototype.set=function(t,r){var e=this.__data__;if(e instanceof X){var n=e.__data__;if(!H||n.length<199)return n.push([t,r]),this.size=++e.size,this;e=this.__data__=new Y(n)}return e.set(t,r),this.size=e.size,this};var it,ut=function(t,r,e){for(var n=-1,o=Object(t),i=e(t),u=i.length;u--;){var c=i[it?u:++n];if(!1===r(o[c],c,o))break}return t};function ct(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":L&&L in Object(t)?function(t){var r=F.call(t,L),e=t[L];try{t[L]=void 0;var n=!0}catch(t){}var o=S.call(t);n&&(r?t[L]=e:delete t[L]);return o}(t):function(t){return S.call(t)}(t)}function at(t){return xt(t)&&ct(t)==o}function ft(t){return!(!Mt(t)||function(t){return!!U&&U in t}(t))&&(At(t)?P:a).test(function(t){if(null!=t){try{return C.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function st(t){if(!Mt(t))return function(t){var r=[];if(null!=t)for(var e in Object(t))r.push(e);return r}(t);var r=dt(t),e=[];for(var n in t)("constructor"!=n||!r&&F.call(t,n))&&e.push(n);return e}function lt(t,r,e,n,o){t!==r&&ut(r,(function(i,u){if(o||(o=new Z),Mt(i))!function(t,r,e,n,o,i,u){var a=yt(t,e),f=yt(r,e),s=u.get(f);if(s)return void rt(t,e,s);var l=i?i(a,f,e+"",t,r,u):void 0,h=void 0===l;if(h){var p=wt(f),_=!p&&mt(f),v=!p&&!_&&Ct(f);l=f,p||_||v?wt(a)?l=a:xt(j=a)&&Ot(j)?l=function(t,r){var e=-1,n=t.length;r||(r=Array(n));for(;++e-1&&t%1==0&&t0){if(++r>=800)return arguments[0]}else r=0;return t.apply(void 0,arguments)}}(R?function(t,r){return R(t,"toString",{configurable:!0,enumerable:!1,value:(e=r,function(){return e}),writable:!0});var e}:It);function bt(t,r){return t===r||t!=t&&r!=r}var jt=at(function(){return arguments}())?at:function(t){return xt(t)&&F.call(t,"callee")&&!B.call(t,"callee")},wt=Array.isArray;function Ot(t){return null!=t&&zt(t.length)&&!At(t)}var mt=G||function(){return!1};function At(t){if(!Mt(t))return!1;var r=ct(t);return r==u||"[object GeneratorFunction]"==r||"[object AsyncFunction]"==r||"[object Proxy]"==r}function zt(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=n}function Mt(t){var r=typeof t;return null!=t&&("object"==r||"function"==r)}function xt(t){return null!=t&&"object"==typeof t}var Ct=b?function(t){return function(r){return t(r)}}(b):function(t){return xt(t)&&zt(t.length)&&!!s[ct(t)]};function Ft(t){return Ot(t)?tt(t,!0):st(t)}var Ut,St=(Ut=function(t,r,e){lt(t,r,e)},ht((function(t,r){var e=-1,n=r.length,o=n>1?r[n-1]:void 0,i=n>2?r[2]:void 0;for(o=Ut.length>3&&"function"==typeof o?(n--,o):void 0,i&&function(t,r,e){if(!Mt(e))return!1;var n=typeof r;return!!("number"==n?Ot(e)&&vt(r,e.length):"string"==n&&r in e)&&bt(e[r],t)}(r[0],r[1],i)&&(o=n<3?void 0:o,n=1),t=Object(t);++ec.call(t,r);class f{constructor({pluginId:t,defaultConfig:r={},customMerge:e,root:n}){this.pluginId=t,this.defaultConfig=r,this.pluginConfigPath=o.default.resolve(n||__dirname,t),this.customMerge=e,this._config=void 0}resolve(t){return o.default.resolve(this.pluginConfigPath,t)}hasFile(t){return n.default.existsSync(this.resolve(t))}requireFile(t){try{return require(this.resolve(t))}catch(t){if("MODULE_NOT_FOUND"===t.code)return;throw t}}_getUserConfig(){return this.requireFile("config.json")}config(t,r){this._config||(this._config=(this.customMerge||u)(this.defaultConfig,this._getUserConfig()));let e=this._config;return t?function(t,r,e){if("number"==typeof r)return t[r];if("symbol"==typeof r)return a(t,r)?t[r]:e;const n="string"!=typeof(o=r)?o:o.split(".").reduce(((t,r)=>(r.split(/\[([^}]+)\]/g).forEach((r=>r&&t.push(r))),t)),[]);var o;let i=t;for(let t=0;t {
+ return (item.dcloudAppid === appid)
+ })
+ }
+ return this._uniId
+ }
+
+ get ready() {
+ return this._ready
+ }
+}
+
+class AppConfig extends ConfigBase {
+
+ constructor() {
+ super()
+ }
+
+ get(appid, platform) {
+ if (!this.isSupport(platform)) {
+ return null
+ }
+
+ let appConfig = this.getAppConfig(appid)
+ if (!appConfig) {
+ return null
+ }
+
+ return this.getOauthConfig(appConfig, platform)
+ }
+
+ isSupport(platformName) {
+ return (AppConfig.Support_Platforms.indexOf(platformName) >= 0)
+ }
+
+ getOauthConfig(appConfig, platformName) {
+ let tree = OauthConfig[platformName]
+ let node = appConfig
+ for (let i = 0; i < tree.length; i++) {
+ let nodeName = tree[i]
+ if (node[nodeName]) {
+ node = node[nodeName]
+ } else {
+ node = null
+ break
+ }
+ }
+
+ if (node && node.appid && node.appsecret) {
+ return {
+ appid: node.appid,
+ secret: node.appsecret
+ }
+ }
+
+ return null
+ }
+}
+
+AppConfig.Support_Platforms = [PlatformType.WEIXIN_MP, PlatformType.WEIXIN_H5]
+
+
+module.exports = {
+ AppConfig
+};
diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-open-bridge-common/consts.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-open-bridge-common/consts.js
new file mode 100644
index 0000000000000000000000000000000000000000..6da817b9620336453e06025815a12d378249ebde
--- /dev/null
+++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-open-bridge-common/consts.js
@@ -0,0 +1,26 @@
+'use strict';
+
+const TAG = "UNI_OPEN_BRIDGE"
+
+const HTTP_STATUS = {
+ SUCCESS: 200
+}
+
+const PlatformType = {
+ WEIXIN_MP: 'weixin-mp',
+ WEIXIN_H5: 'weixin-h5',
+ WEIXIN_APP: 'weixin-app',
+ WEIXIN_WEB: 'weixin-web',
+ QQ_MP: 'qq-mp',
+ QQ_APP: 'qq-app'
+}
+
+const ErrorCodeType = {
+ SYSTEM_ERROR: TAG + "_SYSTEM_ERROR"
+}
+
+module.exports = {
+ HTTP_STATUS,
+ PlatformType,
+ ErrorCodeType
+}
diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-open-bridge-common/index.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-open-bridge-common/index.js
new file mode 100644
index 0000000000000000000000000000000000000000..f39b0af531b251a208a03b3b6c108a65935057a1
--- /dev/null
+++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-open-bridge-common/index.js
@@ -0,0 +1,221 @@
+'use strict';
+
+const {
+ PlatformType,
+ ErrorCodeType
+} = require('./consts.js')
+
+const {
+ AppConfig
+} = require('./config.js')
+
+const {
+ Storage,
+ Factory
+} = require('./storage.js')
+
+const {
+ BridgeError
+} = require('./bridge-error.js')
+
+const {
+ WeixinServer
+} = require('./weixin-server.js')
+
+const appConfig = new AppConfig()
+
+class AccessToken extends Storage {
+
+ constructor() {
+ super('access-token', ['dcloudAppid', 'platform'])
+ }
+
+ async fallback(parameters) {
+ const oauthConfig = appConfig.get(parameters.dcloudAppid, parameters.platform)
+ let methodName
+ if (parameters.platform === PlatformType.WEIXIN_MP) {
+ methodName = 'GetMPAccessTokenData'
+ } else if (parameters.platform === PlatformType.WEIXIN_H5) {
+ methodName = 'GetH5AccessTokenData'
+ } else {
+ throw new BridgeError(ErrorCodeType.SYSTEM_ERROR, "platform invalid")
+ }
+
+ const responseData = await WeixinServer[methodName](oauthConfig)
+
+ const duration = responseData.expires_in || (60 * 60 * 2)
+ delete responseData.expires_in
+
+ return {
+ value: responseData,
+ duration
+ }
+ }
+}
+
+class UserAccessToken extends Storage {
+
+ constructor() {
+ super('user-access-token', ['dcloudAppid', 'platform', 'openid'])
+ }
+}
+
+class SessionKey extends Storage {
+
+ constructor() {
+ super('session-key', ['dcloudAppid', 'platform', 'openid'])
+ }
+}
+
+class Encryptkey extends Storage {
+
+ constructor() {
+ super('encrypt-key', ['dcloudAppid', 'platform', 'openid'])
+ }
+
+ getKeyString(key) {
+ return `${super.getKeyString(key)}-${key.version}`
+ }
+
+ getExpiresIn(value) {
+ if (value <= 0) {
+ return 60
+ }
+ return value
+ }
+
+ async fallback(parameters) {
+ const accessToken = await Factory.Get(AccessToken, parameters)
+ const userSession = await Factory.Get(SessionKey, parameters)
+
+ const responseData = await WeixinServer.GetUserEncryptKeyData({
+ openid: parameters.openid,
+ access_token: accessToken.access_token,
+ session_key: userSession.session_key
+ })
+
+ const keyInfo = responseData.key_info_list.find((item) => {
+ return item.version = parameters.version
+ })
+
+ const value = {
+ encrypt_key: keyInfo.encrypt_key,
+ iv: keyInfo.iv
+ }
+
+ return {
+ value,
+ duration: keyInfo.expire_in
+ }
+ }
+}
+
+class Ticket extends Storage {
+
+ constructor() {
+ super('ticket', ['dcloudAppid', 'platform'])
+ }
+
+ async fallback(parameters) {
+ const accessToken = await Factory.Get(AccessToken, {
+ dcloudAppid: parameters.dcloudAppid,
+ platform: PlatformType.WEIXIN_H5
+ })
+
+ const responseData = await WeixinServer.GetH5TicketData(accessToken)
+
+ const duration = responseData.expires_in || (60 * 60 * 2)
+ delete responseData.expires_in
+ delete responseData.errcode
+ delete responseData.errmsg
+
+ return {
+ value: responseData,
+ duration
+ }
+ }
+}
+
+
+// exports
+
+async function getAccessToken(key, fallback) {
+ return await Factory.Get(AccessToken, key, fallback)
+}
+
+async function setAccessToken(key, value, expiresIn) {
+ await Factory.Set(AccessToken, key, value, expiresIn)
+}
+
+async function removeAccessToken(key) {
+ await Factory.Remove(AccessToken, key)
+}
+
+async function getUserAccessToken(key, fallback) {
+ return await Factory.Get(UserAccessToken, key, fallback)
+}
+
+async function setUserAccessToken(key, value, expiresIn) {
+ await Factory.Set(UserAccessToken, key, value, expiresIn)
+}
+
+async function removeUserAccessToken(key) {
+ await Factory.Remove(UserAccessToken, key)
+}
+
+async function getSessionKey(key, fallback) {
+ return await Factory.Get(SessionKey, key, fallback)
+}
+
+async function setSessionKey(key, value, expiresIn) {
+ await Factory.Set(SessionKey, key, value, expiresIn)
+}
+
+async function removeSessionKey(key) {
+ await Factory.Remove(SessionKey, key)
+}
+
+async function getEncryptKey(key, fallback) {
+ return await Factory.Get(Encryptkey, key, fallback)
+}
+
+async function setEncryptKey(key, value, expiresIn) {
+ await Factory.Set(Encryptkey, key, value, expiresIn)
+}
+
+async function removeEncryptKey(key) {
+ await Factory.Remove(Encryptkey, key)
+}
+
+async function getTicket(key, fallback) {
+ return await Factory.Get(Ticket, key, fallback)
+}
+
+async function setTicket(key, value, expiresIn) {
+ await Factory.Set(Ticket, key, value, expiresIn)
+}
+
+async function removeTicket(key) {
+ await Factory.Remove(Ticket, key)
+}
+
+module.exports = {
+ getAccessToken,
+ setAccessToken,
+ removeAccessToken,
+ getUserAccessToken,
+ setUserAccessToken,
+ removeUserAccessToken,
+ getSessionKey,
+ setSessionKey,
+ removeSessionKey,
+ getEncryptKey,
+ setEncryptKey,
+ removeEncryptKey,
+ getTicket,
+ setTicket,
+ removeTicket,
+ PlatformType,
+ WeixinServer,
+ ErrorCodeType
+}
diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-open-bridge-common/node_modules/uni-config-center/index.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-open-bridge-common/node_modules/uni-config-center/index.js
new file mode 100644
index 0000000000000000000000000000000000000000..e14fb3b0a213443d5c51cb3fcb763d322c21c97f
--- /dev/null
+++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-open-bridge-common/node_modules/uni-config-center/index.js
@@ -0,0 +1 @@
+"use strict";var t=require("fs"),r=require("path");function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=e(t),o=e(r),i="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var u=function(t){var r={exports:{}};return t(r,r.exports),r.exports}((function(t,r){var e="__lodash_hash_undefined__",n=9007199254740991,o="[object Arguments]",u="[object Function]",c="[object Object]",a=/^\[object .+?Constructor\]$/,f=/^(?:0|[1-9]\d*)$/,s={};s["[object Float32Array]"]=s["[object Float64Array]"]=s["[object Int8Array]"]=s["[object Int16Array]"]=s["[object Int32Array]"]=s["[object Uint8Array]"]=s["[object Uint8ClampedArray]"]=s["[object Uint16Array]"]=s["[object Uint32Array]"]=!0,s[o]=s["[object Array]"]=s["[object ArrayBuffer]"]=s["[object Boolean]"]=s["[object DataView]"]=s["[object Date]"]=s["[object Error]"]=s[u]=s["[object Map]"]=s["[object Number]"]=s[c]=s["[object RegExp]"]=s["[object Set]"]=s["[object String]"]=s["[object WeakMap]"]=!1;var l="object"==typeof i&&i&&i.Object===Object&&i,h="object"==typeof self&&self&&self.Object===Object&&self,p=l||h||Function("return this")(),_=r&&!r.nodeType&&r,v=_&&t&&!t.nodeType&&t,d=v&&v.exports===_,y=d&&l.process,g=function(){try{var t=v&&v.require&&v.require("util").types;return t||y&&y.binding&&y.binding("util")}catch(t){}}(),b=g&&g.isTypedArray;function j(t,r,e){switch(e.length){case 0:return t.call(r);case 1:return t.call(r,e[0]);case 2:return t.call(r,e[0],e[1]);case 3:return t.call(r,e[0],e[1],e[2])}return t.apply(r,e)}var w,O,m,A=Array.prototype,z=Function.prototype,M=Object.prototype,x=p["__core-js_shared__"],C=z.toString,F=M.hasOwnProperty,U=(w=/[^.]+$/.exec(x&&x.keys&&x.keys.IE_PROTO||""))?"Symbol(src)_1."+w:"",S=M.toString,I=C.call(Object),P=RegExp("^"+C.call(F).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),T=d?p.Buffer:void 0,q=p.Symbol,E=p.Uint8Array,$=T?T.allocUnsafe:void 0,D=(O=Object.getPrototypeOf,m=Object,function(t){return O(m(t))}),k=Object.create,B=M.propertyIsEnumerable,N=A.splice,L=q?q.toStringTag:void 0,R=function(){try{var t=_t(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),G=T?T.isBuffer:void 0,V=Math.max,W=Date.now,H=_t(p,"Map"),J=_t(Object,"create"),K=function(){function t(){}return function(r){if(!Mt(r))return{};if(k)return k(r);t.prototype=r;var e=new t;return t.prototype=void 0,e}}();function Q(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r-1},X.prototype.set=function(t,r){var e=this.__data__,n=nt(e,t);return n<0?(++this.size,e.push([t,r])):e[n][1]=r,this},Y.prototype.clear=function(){this.size=0,this.__data__={hash:new Q,map:new(H||X),string:new Q}},Y.prototype.delete=function(t){var r=pt(this,t).delete(t);return this.size-=r?1:0,r},Y.prototype.get=function(t){return pt(this,t).get(t)},Y.prototype.has=function(t){return pt(this,t).has(t)},Y.prototype.set=function(t,r){var e=pt(this,t),n=e.size;return e.set(t,r),this.size+=e.size==n?0:1,this},Z.prototype.clear=function(){this.__data__=new X,this.size=0},Z.prototype.delete=function(t){var r=this.__data__,e=r.delete(t);return this.size=r.size,e},Z.prototype.get=function(t){return this.__data__.get(t)},Z.prototype.has=function(t){return this.__data__.has(t)},Z.prototype.set=function(t,r){var e=this.__data__;if(e instanceof X){var n=e.__data__;if(!H||n.length<199)return n.push([t,r]),this.size=++e.size,this;e=this.__data__=new Y(n)}return e.set(t,r),this.size=e.size,this};var it,ut=function(t,r,e){for(var n=-1,o=Object(t),i=e(t),u=i.length;u--;){var c=i[it?u:++n];if(!1===r(o[c],c,o))break}return t};function ct(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":L&&L in Object(t)?function(t){var r=F.call(t,L),e=t[L];try{t[L]=void 0;var n=!0}catch(t){}var o=S.call(t);n&&(r?t[L]=e:delete t[L]);return o}(t):function(t){return S.call(t)}(t)}function at(t){return xt(t)&&ct(t)==o}function ft(t){return!(!Mt(t)||function(t){return!!U&&U in t}(t))&&(At(t)?P:a).test(function(t){if(null!=t){try{return C.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function st(t){if(!Mt(t))return function(t){var r=[];if(null!=t)for(var e in Object(t))r.push(e);return r}(t);var r=dt(t),e=[];for(var n in t)("constructor"!=n||!r&&F.call(t,n))&&e.push(n);return e}function lt(t,r,e,n,o){t!==r&&ut(r,(function(i,u){if(o||(o=new Z),Mt(i))!function(t,r,e,n,o,i,u){var a=yt(t,e),f=yt(r,e),s=u.get(f);if(s)return void rt(t,e,s);var l=i?i(a,f,e+"",t,r,u):void 0,h=void 0===l;if(h){var p=wt(f),_=!p&&mt(f),v=!p&&!_&&Ct(f);l=f,p||_||v?wt(a)?l=a:xt(j=a)&&Ot(j)?l=function(t,r){var e=-1,n=t.length;r||(r=Array(n));for(;++e-1&&t%1==0&&t0){if(++r>=800)return arguments[0]}else r=0;return t.apply(void 0,arguments)}}(R?function(t,r){return R(t,"toString",{configurable:!0,enumerable:!1,value:(e=r,function(){return e}),writable:!0});var e}:It);function bt(t,r){return t===r||t!=t&&r!=r}var jt=at(function(){return arguments}())?at:function(t){return xt(t)&&F.call(t,"callee")&&!B.call(t,"callee")},wt=Array.isArray;function Ot(t){return null!=t&&zt(t.length)&&!At(t)}var mt=G||function(){return!1};function At(t){if(!Mt(t))return!1;var r=ct(t);return r==u||"[object GeneratorFunction]"==r||"[object AsyncFunction]"==r||"[object Proxy]"==r}function zt(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=n}function Mt(t){var r=typeof t;return null!=t&&("object"==r||"function"==r)}function xt(t){return null!=t&&"object"==typeof t}var Ct=b?function(t){return function(r){return t(r)}}(b):function(t){return xt(t)&&zt(t.length)&&!!s[ct(t)]};function Ft(t){return Ot(t)?tt(t,!0):st(t)}var Ut,St=(Ut=function(t,r,e){lt(t,r,e)},ht((function(t,r){var e=-1,n=r.length,o=n>1?r[n-1]:void 0,i=n>2?r[2]:void 0;for(o=Ut.length>3&&"function"==typeof o?(n--,o):void 0,i&&function(t,r,e){if(!Mt(e))return!1;var n=typeof r;return!!("number"==n?Ot(e)&&vt(r,e.length):"string"==n&&r in e)&&bt(e[r],t)}(r[0],r[1],i)&&(o=n<3?void 0:o,n=1),t=Object(t);++ec.call(t,r);class f{constructor({pluginId:t,defaultConfig:r={},customMerge:e,root:n}){this.pluginId=t,this.defaultConfig=r,this.pluginConfigPath=o.default.resolve(n||__dirname,t),this.customMerge=e,this._config=void 0}resolve(t){return o.default.resolve(this.pluginConfigPath,t)}hasFile(t){return n.default.existsSync(this.resolve(t))}requireFile(t){try{return require(this.resolve(t))}catch(t){if("MODULE_NOT_FOUND"===t.code)return;throw t}}_getUserConfig(){return this.requireFile("config.json")}config(t,r){this._config||(this._config=(this.customMerge||u)(this.defaultConfig,this._getUserConfig()));let e=this._config;return t?function(t,r,e){if("number"==typeof r)return t[r];if("symbol"==typeof r)return a(t,r)?t[r]:e;const n="string"!=typeof(o=r)?o:o.split(".").reduce(((t,r)=>(r.split(/\[([^}]+)\]/g).forEach((r=>r&&t.push(r))),t)),[]);var o;let i=t;for(let t=0;t {
+ keyArray.push(key[name])
+ })
+ keyArray.push(this._type)
+ return keyArray.join(':')
+ }
+
+ getValue(value) {
+ return value
+ }
+
+ getExpiresIn(value) {
+ if (value !== undefined) {
+ return value
+ }
+ return -1
+ }
+
+ validateKey(key) {
+ Validator.Key(this._keys, key)
+ }
+
+ validateValue(value) {
+ Validator.Value(value)
+ }
+
+ create(key, fallback) {
+ const keyString = this.getKeyString(key)
+ const options = {
+ layers: [{
+ type: 'database',
+ key: keyString
+ }, {
+ type: 'redis',
+ key: keyString
+ }]
+ }
+ if (fallback !== null) {
+ const fallbackFunction = fallback || this.fallback
+ if (fallbackFunction) {
+ options.fallback = async () => {
+ return await fallbackFunction(key)
+ }
+ }
+ }
+ return new CacheKeyCascade(options)
+ }
+}
+Storage.Prefix = "uni-id"
+
+const Factory = {
+
+ async Get(T, key, fallback) {
+ return await Factory.MakeUnique(T).get(key, fallback)
+ },
+
+ async Set(T, key, value, expiresIn) {
+ await Factory.MakeUnique(T).set(key, value, expiresIn)
+ },
+
+ async Remove(T, key) {
+ await Factory.MakeUnique(T).remove(key)
+ },
+
+ MakeUnique(T) {
+ return new T()
+ }
+}
+
+module.exports = {
+ Storage,
+ Factory
+};
diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-open-bridge-common/uni-cloud-cache.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-open-bridge-common/uni-cloud-cache.js
new file mode 100644
index 0000000000000000000000000000000000000000..2e4286be42be9f447b22f199e70e670af9416db4
--- /dev/null
+++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-open-bridge-common/uni-cloud-cache.js
@@ -0,0 +1,324 @@
+const db = uniCloud.database()
+
+function getType(value) {
+ return Object.prototype.toString.call(value).slice(8, -1).toLowerCase()
+}
+
+const validator = {
+ key: function(value) {
+ const err = new Error('Invalid key')
+ if (typeof value !== 'string') {
+ throw err
+ }
+ const valueTrim = value.trim()
+ if (!valueTrim || valueTrim !== value) {
+ throw err
+ }
+ },
+ value: function(value) {
+ // 仅作简单校验
+ const type = getType(value)
+ const validValueType = ['null', 'number', 'string', 'array', 'object']
+ if (validValueType.indexOf(type) === -1) {
+ throw new Error('Invalid value type')
+ }
+ },
+ duration: function(value) {
+ const err = new Error('Invalid duration')
+ if (value === undefined) {
+ return
+ }
+ if (typeof value !== 'number' || value === 0) {
+ throw err
+ }
+ }
+}
+
+/**
+ * 入库时 expired 为过期时间对应的时间戳,永不过期用-1表示
+ * 返回结果时 与redis对齐,-1表示永不过期,-2表示已过期或不存在
+ */
+class DatabaseCache {
+ constructor({
+ collection = 'opendb-open-data'
+ } = {}) {
+ this.type = 'db'
+ this.collection = db.collection(collection)
+ }
+
+ _serializeValue(value) {
+ return value === undefined ? null : JSON.stringify(value)
+ }
+
+ _deserializeValue(value) {
+ return value ? JSON.parse(value) : value
+ }
+
+ async set(key, value, duration) {
+ validator.key(key)
+ validator.value(value)
+ validator.duration(duration)
+ value = this._serializeValue(value)
+ await this.collection.doc(key).set({
+ value,
+ expired: duration && duration !== -1 ? Date.now() + (duration * 1000) : -1
+ })
+ }
+
+ async _getWithDuration(key) {
+ const getKeyRes = await this.collection.doc(key).get()
+ const record = getKeyRes.data[0]
+ if (!record) {
+ return {
+ value: null,
+ duration: -2
+ }
+ }
+ const value = this._deserializeValue(record.value)
+ const expired = record.expired
+ if (expired === -1) {
+ return {
+ value,
+ duration: -1
+ }
+ }
+ const duration = expired - Date.now()
+ if (duration <= 0) {
+ await this.remove(key)
+ return {
+ value: null,
+ duration: -2
+ }
+ }
+ return {
+ value,
+ duration: Math.floor(duration / 1000)
+ }
+ }
+
+ async get(key, {
+ withDuration = true
+ } = {}) {
+ const result = await this._getWithDuration(key)
+ if (!withDuration) {
+ delete result.duration
+ }
+ return result
+ }
+
+ async remove(key) {
+ await this.collection.doc(key).remove()
+ }
+}
+
+class RedisCache {
+ constructor() {
+ this.type = 'redis'
+ this.redis = uniCloud.redis()
+ }
+
+ _serializeValue(value) {
+ return value === undefined ? null : JSON.stringify(value)
+ }
+
+ _deserializeValue(value) {
+ return value ? JSON.parse(value) : value
+ }
+
+ async set(key, value, duration) {
+ validator.key(key)
+ validator.value(value)
+ validator.duration(duration)
+ value = this._serializeValue(value)
+ if (!duration || duration === -1) {
+ await this.redis.set(key, value)
+ } else {
+ await this.redis.set(key, value, 'EX', duration)
+ }
+ }
+
+ async get(key, {
+ withDuration = false
+ } = {}) {
+ let value = await this.redis.get(key)
+ value = this._deserializeValue(value)
+ if (!withDuration) {
+ return {
+ value
+ }
+ }
+ const durationSecond = await this.redis.ttl(key)
+ let duration
+ switch (durationSecond) {
+ case -1:
+ duration = -1
+ break
+ case -2:
+ duration = -2
+ break
+ default:
+ duration = durationSecond
+ break
+ }
+ return {
+ value,
+ duration
+ }
+ }
+
+ async remove(key) {
+ await this.redis.del(key)
+ }
+}
+
+class Cache {
+ constructor({
+ type,
+ collection
+ } = {}) {
+ if (type === 'database') {
+ return new DatabaseCache({
+ collection
+ })
+ } else if (type === 'redis') {
+ return new RedisCache()
+ } else {
+ throw new Error('Invalid cache type')
+ }
+ }
+}
+
+class CacheKey {
+ constructor({
+ type,
+ collection,
+ cache,
+ key,
+ fallback
+ } = {}) {
+ this.cache = cache || new Cache({
+ type,
+ collection
+ })
+ this.key = key
+ this.fallback = fallback
+ }
+
+ async set(value, duration) {
+ await this.cache.set(this.key, value, duration)
+ }
+
+ async setWithSync(value, duration, syncMethod) {
+ await Promise.all([
+ this.set(this.key, value, duration),
+ syncMethod(value, duration)
+ ])
+ }
+
+ async get() {
+ let {
+ value,
+ duration
+ } = await this.cache.get(this.key)
+ if (value !== null && value !== undefined) {
+ return {
+ value,
+ duration
+ }
+ }
+ if (!this.fallback) {
+ return {
+ value: null,
+ duration: -2
+ }
+ }
+ const fallbackResult = await this.fallback()
+ value = fallbackResult.value
+ duration = fallbackResult.duration
+ if (value !== null && duration !== undefined) {
+ await this.cache.set(this.key, value, duration)
+ }
+ return {
+ value,
+ duration
+ }
+ }
+
+ async remove() {
+ await this.cache.remove(this.key)
+ }
+}
+
+class CacheKeyCascade {
+ constructor({
+ layers, // [{cache, type, collection, key}] 从低级到高级排序,[DbCacheKey, RedisCacheKey]
+ fallback
+ } = {}) {
+ this.layers = layers
+ this.cacheLayers = []
+ let lastCacheKey
+ for (let i = 0; i < layers.length; i++) {
+ const {
+ type,
+ cache,
+ collection,
+ key
+ } = layers[i]
+ const lastCacheKeyTemp = lastCacheKey
+ try {
+ const currentCacheKey = new CacheKey({
+ type,
+ collection,
+ cache,
+ key,
+ fallback: i === 0 ? fallback : function() {
+ return lastCacheKeyTemp.get()
+ }
+ })
+ this.cacheLayers.push(currentCacheKey)
+ lastCacheKey = currentCacheKey
+ } catch (e) {}
+ }
+ this.highLevelCache = lastCacheKey
+ }
+
+ async set(value, duration) {
+ return Promise.all(
+ this.cacheLayers.map(item => {
+ return item.set(value, duration)
+ })
+ )
+ }
+
+ async setWithSync(value, duration, syncMethod) {
+ const setPromise = this.cacheLayers.map(item => {
+ return item.set(value, duration)
+ })
+ return Promise.all(
+ [
+ ...setPromise,
+ syncMethod(value, duration)
+ ]
+ )
+ }
+
+ async get() {
+ return this.highLevelCache.get()
+ }
+
+ async remove() {
+ await Promise.all(
+ this.cacheLayers.map(cacheKeyItem => {
+ return cacheKeyItem.remove()
+ })
+ )
+ }
+}
+
+module.exports = {
+ Cache,
+ DatabaseCache,
+ RedisCache,
+ CacheKey,
+ CacheKeyCascade
+}
diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-open-bridge-common/validator.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-open-bridge-common/validator.js
new file mode 100644
index 0000000000000000000000000000000000000000..47a455b15a479ce608838731287f5776985e191c
--- /dev/null
+++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-open-bridge-common/validator.js
@@ -0,0 +1,31 @@
+const Validator = {
+
+ Key(keyArray, parameters) {
+ for (let i = 0; i < keyArray.length; i++) {
+ const keyName = keyArray[i]
+ if (typeof parameters[keyName] !== 'string') {
+ Validator.ThrowNewError(`Invalid ${keyName}`)
+ }
+ if (parameters[keyName].length < 1) {
+ Validator.ThrowNewError(`Invalid ${keyName}`)
+ }
+ }
+ },
+
+ Value(value) {
+ if (value === undefined) {
+ Validator.ThrowNewError('Invalid Value')
+ }
+ if (typeof value !== 'object') {
+ Validator.ThrowNewError('Invalid Value Type')
+ }
+ },
+
+ ThrowNewError(message) {
+ throw new Error(message)
+ }
+}
+
+module.exports = {
+ Validator
+}
diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-open-bridge-common/weixin-server.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-open-bridge-common/weixin-server.js
new file mode 100644
index 0000000000000000000000000000000000000000..0a0c811338d5c7d83f816c71d1189cd29e16ffd2
--- /dev/null
+++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/node_modules/uni-open-bridge-common/weixin-server.js
@@ -0,0 +1,202 @@
+'use strict';
+
+const crypto = require('crypto')
+
+const {
+ HTTP_STATUS
+} = require('./consts.js')
+
+const {
+ BridgeError
+} = require('./bridge-error.js')
+
+class WeixinServer {
+
+ constructor(options = {}) {
+ this._appid = options.appid
+ this._secret = options.secret
+ }
+
+ getAccessToken() {
+ return uniCloud.httpclient.request(WeixinServer.AccessToken_Url, {
+ dataType: 'json',
+ method: 'POST',
+ data: {
+ appid: this._appid,
+ secret: this._secret,
+ grant_type: "client_credential"
+ }
+ })
+ }
+
+ // 使用客户端获取的 code 从微信服务器换取 openid,code 仅可使用一次
+ codeToSession(code) {
+ return uniCloud.httpclient.request(WeixinServer.Code2Session_Url, {
+ dataType: 'json',
+ data: {
+ appid: this._appid,
+ secret: this._secret,
+ js_code: code,
+ grant_type: 'authorization_code'
+ }
+ })
+ }
+
+ getUserEncryptKey({
+ access_token,
+ openid,
+ session_key
+ }) {
+ console.log(access_token, openid, session_key);
+ const signature = crypto.createHmac('sha256', session_key).update('').digest('hex')
+ return uniCloud.httpclient.request(WeixinServer.User_Encrypt_Key_Url, {
+ dataType: 'json',
+ method: 'POST',
+ dataAsQueryString: true,
+ data: {
+ access_token,
+ openid: openid,
+ signature: signature,
+ sig_method: 'hmac_sha256'
+ }
+ })
+ }
+
+ getH5AccessToken() {
+ return uniCloud.httpclient.request(WeixinServer.AccessToken_H5_Url, {
+ dataType: 'json',
+ method: 'GET',
+ data: {
+ appid: this._appid,
+ secret: this._secret,
+ grant_type: "client_credential"
+ }
+ })
+ }
+
+ getH5Ticket(access_token) {
+ return uniCloud.httpclient.request(WeixinServer.Ticket_Url, {
+ dataType: 'json',
+ dataAsQueryString: true,
+ method: 'POST',
+ data: {
+ access_token
+ }
+ })
+ }
+
+ getH5AccessTokenForEip() {
+ return uniCloud.httpProxyForEip.postForm(WeixinServer.AccessToken_H5_Url, {
+ appid: this._appid,
+ secret: this._secret,
+ grant_type: "client_credential"
+ }, {
+ dataType: 'json'
+ })
+ }
+
+ getH5TicketForEip(access_token) {
+ return uniCloud.httpProxyForEip.postForm(WeixinServer.Ticket_Url, {
+ access_token
+ }, {
+ dataType: 'json',
+ dataAsQueryString: true
+ })
+ }
+}
+
+WeixinServer.AccessToken_Url = 'https://api.weixin.qq.com/cgi-bin/token'
+WeixinServer.Code2Session_Url = 'https://api.weixin.qq.com/sns/jscode2session'
+WeixinServer.User_Encrypt_Key_Url = 'https://api.weixin.qq.com/wxa/business/getuserencryptkey'
+WeixinServer.AccessToken_H5_Url = 'https://api.weixin.qq.com/cgi-bin/token'
+WeixinServer.Ticket_Url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi'
+
+WeixinServer.GetMPAccessToken = function(options) {
+ return new WeixinServer(options).getAccessToken()
+}
+
+WeixinServer.GetCodeToSession = function(options) {
+ return new WeixinServer(options).codeToSession(options.code)
+}
+
+WeixinServer.GetUserEncryptKey = function(options) {
+ return new WeixinServer(options).getUserEncryptKey(options)
+}
+
+WeixinServer.GetH5AccessToken = function(options) {
+ return new WeixinServer(options).getH5AccessToken()
+}
+
+WeixinServer.GetH5Ticket = function(options) {
+ return new WeixinServer(options).getH5Ticket(options.access_token)
+}
+
+////////////////////////////////////////////////////////////////
+
+function isAliyun() {
+ return (uniCloud.getCloudInfos()[0].provider === 'aliyun')
+}
+
+WeixinServer.GetResponseData = function(response) {
+ console.log("WeixinServer::response", response)
+
+ if (!(response.status === HTTP_STATUS.SUCCESS || response.statusCodeValue === HTTP_STATUS.SUCCESS)) {
+ throw new BridgeError(response.status || response.statusCodeValue, response.status || response.statusCodeValue)
+ }
+
+ const responseData = response.data || response.body
+
+ if (responseData.errcode !== undefined && responseData.errcode !== 0) {
+ throw new BridgeError(responseData.errcode, responseData.errmsg)
+ }
+
+ return responseData
+}
+
+WeixinServer.GetMPAccessTokenData = async function(options) {
+ const response = await new WeixinServer(options).getAccessToken()
+ return WeixinServer.GetResponseData(response)
+}
+
+WeixinServer.GetCodeToSessionData = async function(options) {
+ const response = await new WeixinServer(options).codeToSession(options.code)
+ return WeixinServer.GetResponseData(response)
+}
+
+WeixinServer.GetUserEncryptKeyData = async function(options) {
+ const response = await new WeixinServer(options).getUserEncryptKey(options)
+ return WeixinServer.GetResponseData(response)
+}
+
+WeixinServer.GetH5AccessTokenData = async function(options) {
+ const ws = new WeixinServer(options)
+ let response
+ if (isAliyun()) {
+ response = await ws.getH5AccessTokenForEip()
+ if (typeof response === 'string') {
+ response = JSON.parse(response)
+ }
+ } else {
+ response = await ws.getH5AccessToken()
+ }
+ return WeixinServer.GetResponseData(response)
+}
+
+WeixinServer.GetH5TicketData = async function(options) {
+ const ws = new WeixinServer(options)
+ let response
+ if (isAliyun()) {
+ response = await ws.getH5TicketForEip(options.access_token)
+ if (typeof response === 'string') {
+ response = JSON.parse(response)
+ }
+ } else {
+ response = await ws.getH5Ticket(options.access_token)
+ }
+ return WeixinServer.GetResponseData(response)
+}
+
+
+module.exports = {
+ WeixinServer
+}
diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/package-lock.json b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/package-lock.json
new file mode 100644
index 0000000000000000000000000000000000000000..56529b2dd7f45bd6ede4ba04474c2e3e680da2d9
--- /dev/null
+++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/package-lock.json
@@ -0,0 +1,148 @@
+{
+ "name": "uni-id-co",
+ "version": "1.0.27",
+ "lockfileVersion": 1,
+ "requires": true,
+ "dependencies": {
+ "buffer-equal-constant-time": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz",
+ "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA=="
+ },
+ "ecdsa-sig-formatter": {
+ "version": "1.0.11",
+ "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
+ "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==",
+ "requires": {
+ "safe-buffer": "^5.0.1"
+ }
+ },
+ "jsonwebtoken": {
+ "version": "8.5.1",
+ "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz",
+ "integrity": "sha512-XjwVfRS6jTMsqYs0EsuJ4LGxXV14zQybNd4L2r0UvbVnSF9Af8x7p5MzbJ90Ioz/9TI41/hTCvznF/loiSzn8w==",
+ "requires": {
+ "jws": "^3.2.2",
+ "lodash.includes": "^4.3.0",
+ "lodash.isboolean": "^3.0.3",
+ "lodash.isinteger": "^4.0.4",
+ "lodash.isnumber": "^3.0.3",
+ "lodash.isplainobject": "^4.0.6",
+ "lodash.isstring": "^4.0.1",
+ "lodash.once": "^4.0.0",
+ "ms": "^2.1.1",
+ "semver": "^5.6.0"
+ }
+ },
+ "jwa": {
+ "version": "1.4.1",
+ "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.1.tgz",
+ "integrity": "sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==",
+ "requires": {
+ "buffer-equal-constant-time": "1.0.1",
+ "ecdsa-sig-formatter": "1.0.11",
+ "safe-buffer": "^5.0.1"
+ }
+ },
+ "jws": {
+ "version": "3.2.2",
+ "resolved": "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz",
+ "integrity": "sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==",
+ "requires": {
+ "jwa": "^1.4.1",
+ "safe-buffer": "^5.0.1"
+ }
+ },
+ "lodash.includes": {
+ "version": "4.3.0",
+ "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz",
+ "integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w=="
+ },
+ "lodash.isboolean": {
+ "version": "3.0.3",
+ "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz",
+ "integrity": "sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg=="
+ },
+ "lodash.isinteger": {
+ "version": "4.0.4",
+ "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz",
+ "integrity": "sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA=="
+ },
+ "lodash.isnumber": {
+ "version": "3.0.3",
+ "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz",
+ "integrity": "sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw=="
+ },
+ "lodash.isplainobject": {
+ "version": "4.0.6",
+ "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz",
+ "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA=="
+ },
+ "lodash.isstring": {
+ "version": "4.0.1",
+ "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz",
+ "integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw=="
+ },
+ "lodash.merge": {
+ "version": "4.6.2",
+ "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz",
+ "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ=="
+ },
+ "lodash.once": {
+ "version": "4.1.1",
+ "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz",
+ "integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg=="
+ },
+ "ms": {
+ "version": "2.1.3",
+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
+ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="
+ },
+ "safe-buffer": {
+ "version": "5.2.1",
+ "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
+ "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="
+ },
+ "semver": {
+ "version": "5.7.1",
+ "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz",
+ "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ=="
+ },
+ "uni-captcha": {
+ "version": "file:../../../../uni-captcha/uniCloud/cloudfunctions/common/uni-captcha",
+ "requires": {
+ "uni-config-center": "file:../../../../uni-config-center/uniCloud/cloudfunctions/common/uni-config-center"
+ },
+ "dependencies": {
+ "uni-config-center": {
+ "version": "file:../../../../uni-config-center/uniCloud/cloudfunctions/common/uni-config-center"
+ }
+ }
+ },
+ "uni-config-center": {
+ "version": "file:../../../../uni-config-center/uniCloud/cloudfunctions/common/uni-config-center"
+ },
+ "uni-id-common": {
+ "version": "file:../../../../uni-id-common/uniCloud/cloudfunctions/common/uni-id-common",
+ "requires": {
+ "uni-config-center": "file:../../../../uni-config-center/uniCloud/cloudfunctions/common/uni-config-center"
+ },
+ "dependencies": {
+ "uni-config-center": {
+ "version": "file:../../../../uni-config-center/uniCloud/cloudfunctions/common/uni-config-center"
+ }
+ }
+ },
+ "uni-open-bridge-common": {
+ "version": "file:../../../../uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common",
+ "requires": {
+ "uni-config-center": "file:../../../../uni-config-center/uniCloud/cloudfunctions/common/uni-config-center"
+ },
+ "dependencies": {
+ "uni-config-center": {
+ "version": "file:../../../../uni-config-center/uniCloud/cloudfunctions/common/uni-config-center"
+ }
+ }
+ }
+ }
+}
diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/package.json b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/package.json
new file mode 100644
index 0000000000000000000000000000000000000000..6cd370a96d139a072d682afa54f953507f4a3502
--- /dev/null
+++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/package.json
@@ -0,0 +1,23 @@
+{
+ "name": "uni-id-co",
+ "version": "1.0.27",
+ "description": "",
+ "main": "index.js",
+ "keywords": [],
+ "author": "DCloud",
+ "dependencies": {
+ "jsonwebtoken": "8.5.1",
+ "lodash.merge": "^4.6.2",
+ "uni-captcha": "file:../../../../uni-captcha/uniCloud/cloudfunctions/common/uni-captcha",
+ "uni-config-center": "file:../../../../uni-config-center/uniCloud/cloudfunctions/common/uni-config-center",
+ "uni-id-common": "file:../../../../uni-id-common/uniCloud/cloudfunctions/common/uni-id-common",
+ "uni-open-bridge-common": "file:../../../../uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common"
+ },
+ "extensions": {
+ "uni-cloud-sms": {},
+ "uni-cloud-redis": {}
+ },
+ "cloudfunction-config": {
+ "keepRunningAfterReturn": false
+ }
+}
diff --git a/uni_modules/uni-id-pages/uniCloud/database/opendb-device.schema.json b/uni_modules/uni-id-pages/uniCloud/database/opendb-device.schema.json
new file mode 100644
index 0000000000000000000000000000000000000000..c3591cc1f135350f01944d73c6451178a617605f
--- /dev/null
+++ b/uni_modules/uni-id-pages/uniCloud/database/opendb-device.schema.json
@@ -0,0 +1,142 @@
+{
+ "bsonType": "object",
+ "required": [],
+ "permission": {
+ "read": false,
+ "create": true,
+ "update": false,
+ "delete": false
+ },
+ "properties": {
+ "_id": {
+ "description": "ID,系统自动生成"
+ },
+ "appid": {
+ "bsonType": "string",
+ "description": "DCloud appid"
+ },
+ "device_id": {
+ "bsonType": "string",
+ "description": "设备唯一标识"
+ },
+ "vendor": {
+ "bsonType": "string",
+ "description": "设备厂商"
+ },
+ "push_clientid": {
+ "bsonType": "string",
+ "description": "推送设备客户端标识"
+ },
+ "imei": {
+ "bsonType": "string",
+ "description": "国际移动设备识别码IMEI(International Mobile Equipment Identity)"
+ },
+ "oaid": {
+ "bsonType": "string",
+ "description": "移动智能设备标识公共服务平台提供的匿名设备标识符(OAID)"
+ },
+ "idfa": {
+ "bsonType": "string",
+ "description": "iOS平台配置应用使用广告标识(IDFA)"
+ },
+ "imsi": {
+ "bsonType": "string",
+ "description": "国际移动用户识别码(International Mobile Subscriber Identification Number)"
+ },
+ "model": {
+ "bsonType": "string",
+ "description": "设备型号"
+ },
+ "platform": {
+ "bsonType": "string",
+ "description": "平台类型"
+ },
+ "uni_platform": {
+ "bsonType": "string",
+ "description": "uni-app 运行平台,与条件编译平台相同。"
+ },
+ "os_name": {
+ "bsonType": "string",
+ "description": "ios|android|windows|mac|linux "
+ },
+ "os_version": {
+ "bsonType": "string",
+ "description": "操作系统版本号 "
+ },
+ "os_language": {
+ "bsonType": "string",
+ "description": "操作系统语言 "
+ },
+ "os_theme": {
+ "bsonType": "string",
+ "description": "操作系统主题 light|dark"
+ },
+ "pixel_ratio": {
+ "bsonType": "string",
+ "description": "设备像素比 "
+ },
+ "network_model": {
+ "bsonType": "string",
+ "description": "设备网络型号wifi\/3G\/4G\/"
+ },
+ "window_width": {
+ "bsonType": "string",
+ "description": "设备窗口宽度 "
+ },
+ "window_height": {
+ "bsonType": "string",
+ "description": "设备窗口高度"
+ },
+ "screen_width": {
+ "bsonType": "string",
+ "description": "设备屏幕宽度"
+ },
+ "screen_height": {
+ "bsonType": "string",
+ "description": "设备屏幕高度"
+ },
+ "rom_name": {
+ "bsonType": "string",
+ "description": "rom 名称"
+ },
+ "rom_version": {
+ "bsonType": "string",
+ "description": "rom 版本"
+ },
+ "location_latitude": {
+ "bsonType": "double",
+ "description": "纬度"
+ },
+ "location_longitude": {
+ "bsonType": "double",
+ "description": "经度"
+ },
+ "location_country": {
+ "bsonType": "string",
+ "description": "国家"
+ },
+ "location_province": {
+ "bsonType": "string",
+ "description": "省份"
+ },
+ "location_city": {
+ "bsonType": "string",
+ "description": "城市"
+ },
+ "create_date": {
+ "bsonType": "timestamp",
+ "description": "创建时间",
+ "forceDefaultValue": {
+ "$env": "now"
+ }
+ },
+ "last_update_date": {
+ "bsonType": "timestamp",
+ "description": "最后一次修改时间",
+ "forceDefaultValue": {
+ "$env": "now"
+ }
+ }
+ },
+ "version": "0.0.1"
+}
\ No newline at end of file
diff --git a/uni_modules/uni-id-pages/uniCloud/database/uni-id-device.schema.json b/uni_modules/uni-id-pages/uniCloud/database/uni-id-device.schema.json
new file mode 100644
index 0000000000000000000000000000000000000000..4981d75215fc48da914738bca125aedbe0aefac8
--- /dev/null
+++ b/uni_modules/uni-id-pages/uniCloud/database/uni-id-device.schema.json
@@ -0,0 +1,83 @@
+{
+ "bsonType": "object",
+ "required": [
+ "user_id"
+ ],
+ "properties": {
+ "_id": {
+ "description": "ID,系统自动生成"
+ },
+ "user_id": {
+ "bsonType": "string",
+ "description": "用户id,参考uni-id-users表"
+ },
+ "ua": {
+ "bsonType": "string",
+ "description": "userAgent"
+ },
+ "uuid": {
+ "bsonType": "string",
+ "description": "设备唯一标识(需要加密存储)"
+ },
+ "os_name": {
+ "bsonType": "string",
+ "description": "ios|android|windows|mac|linux "
+ },
+ "os_version": {
+ "bsonType": "string",
+ "description": "操作系统版本号 "
+ },
+ "os_language": {
+ "bsonType": "string",
+ "description": "操作系统语言 "
+ },
+ "os_theme": {
+ "bsonType": "string",
+ "description": "操作系统主题 light|dark"
+ },
+ "vendor": {
+ "bsonType": "string",
+ "description": "设备厂商"
+ },
+ "push_clientid": {
+ "bsonType": "string",
+ "description": "推送设备客户端标识"
+ },
+ "imei": {
+ "bsonType": "string",
+ "description": "国际移动设备识别码IMEI(International Mobile Equipment Identity)"
+ },
+ "oaid": {
+ "bsonType": "string",
+ "description": "移动智能设备标识公共服务平台提供的匿名设备标识符(OAID)"
+ },
+ "idfa": {
+ "bsonType": "string",
+ "description": "iOS平台配置应用使用广告标识(IDFA)"
+ },
+ "model": {
+ "bsonType": "string",
+ "description": "设备型号"
+ },
+ "platform": {
+ "bsonType": "string",
+ "description": "平台类型"
+ },
+ "create_date": {
+ "bsonType": "timestamp",
+ "description": "创建时间",
+ "forceDefaultValue": {
+ "$env": "now"
+ }
+ },
+ "last_active_date": {
+ "bsonType": "timestamp",
+ "description": "最后登录时间"
+ },
+ "last_active_ip": {
+ "bsonType": "string",
+ "description": "最后登录IP"
+ }
+ },
+ "version": "0.0.1"
+}
\ No newline at end of file
diff --git a/uni_modules/uni-id-pages/uniCloud/database/uni-id-log.schema.json b/uni_modules/uni-id-pages/uniCloud/database/uni-id-log.schema.json
new file mode 100644
index 0000000000000000000000000000000000000000..ff4f7973239e6aaa467c3278f96462312ca2d71c
--- /dev/null
+++ b/uni_modules/uni-id-pages/uniCloud/database/uni-id-log.schema.json
@@ -0,0 +1,71 @@
+{
+ "bsonType": "object",
+ "required": ["user_id"],
+ "permission": {
+ "read": "'READ_UNI_ID_LOG' in auth.permission"
+ },
+ "properties": {
+ "_id": {
+ "description": "ID,系统自动生成"
+ },
+ "create_date": {
+ "bsonType": "timestamp",
+ "description": "创建时间",
+ "forceDefaultValue": {
+ "$env": "now"
+ }
+ },
+ "device_uuid": {
+ "bsonType": "string",
+ "description": "设备唯一标识"
+ },
+ "ip": {
+ "bsonType": "string",
+ "description": "ip地址"
+ },
+ "state": {
+ "bsonType": "int",
+ "description": "结果:0 失败、1 成功"
+ },
+ "type": {
+ "bsonType": "string",
+ "description": "操作类型",
+ "enum": [
+ "logout",
+ "login",
+ "register",
+ "reset-pwd",
+ "bind-mobile",
+ "bind-weixin",
+ "bind-qq",
+ "bind-apple",
+ "bind-alipay"
+ ]
+ },
+ "ua": {
+ "bsonType": "string",
+ "description": "userAgent"
+ },
+ "user_id": {
+ "bsonType": "string",
+ "foreignKey": "uni-id-users._id",
+ "description": "用户id,参考uni-id-users表"
+ },
+ "username": {
+ "bsonType": "string",
+ "description": "用户名"
+ },
+ "email": {
+ "bsonType": "string",
+ "description": "邮箱"
+ },
+ "mobile": {
+ "bsonType": "string",
+ "description": "手机号"
+ },
+ "appid": {
+ "bsonType": "string",
+ "description": "客户端DCloud AppId"
+ }
+ }
+}
diff --git a/uni_modules/uni-id-pages/uniCloud/database/uni-id-permissions.schema.json b/uni_modules/uni-id-pages/uniCloud/database/uni-id-permissions.schema.json
new file mode 100644
index 0000000000000000000000000000000000000000..25209cbae804642e5065a89148d90de550965666
--- /dev/null
+++ b/uni_modules/uni-id-pages/uniCloud/database/uni-id-permissions.schema.json
@@ -0,0 +1,52 @@
+{
+ "bsonType": "object",
+ "required": ["permission_id", "permission_name"],
+ "permission": {
+ "read": "'READ_UNI_ID_PERMISSIONS' in auth.permission",
+ "create": "'CREATE_UNI_ID_PERMISSIONS' in auth.permission",
+ "update": "'UPDATE_UNI_ID_PERMISSIONS' in auth.permission",
+ "delete": "'DELETE_UNI_ID_PERMISSIONS' in auth.permission"
+ },
+ "properties": {
+ "_id": {
+ "description": "存储文档 ID,系统自动生成"
+ },
+ "comment": {
+ "bsonType": "string",
+ "component": {
+ "name": "textarea"
+ },
+ "description": "备注",
+ "label": "备注",
+ "title": "备注",
+ "trim": "both"
+ },
+ "create_date": {
+ "bsonType": "timestamp",
+ "description": "创建时间",
+ "forceDefaultValue": {
+ "$env": "now"
+ }
+ },
+ "permission_id": {
+ "bsonType": "string",
+ "component": {
+ "name": "input"
+ },
+ "description": "权限唯一标识,不可修改,不允许重复",
+ "label": "权限标识",
+ "title": "权限ID",
+ "trim": "both"
+ },
+ "permission_name": {
+ "bsonType": "string",
+ "component": {
+ "name": "input"
+ },
+ "description": "权限名称",
+ "label": "权限名称",
+ "title": "权限名称",
+ "trim": "both"
+ }
+ }
+}
diff --git a/uni_modules/uni-id-pages/uniCloud/database/uni-id-roles.schema.json b/uni_modules/uni-id-pages/uniCloud/database/uni-id-roles.schema.json
new file mode 100644
index 0000000000000000000000000000000000000000..e2fe3220ccdd6e695ebb70909c2595c1f3242a0a
--- /dev/null
+++ b/uni_modules/uni-id-pages/uniCloud/database/uni-id-roles.schema.json
@@ -0,0 +1,50 @@
+{
+ "bsonType": "object",
+ "required": ["role_id", "role_name"],
+ "permission": {
+ "read": "'READ_UNI_ID_ROLES' in auth.permission",
+ "create": "'CREATE_UNI_ID_ROLES' in auth.permission",
+ "update": "'UPDATE_UNI_ID_ROLES' in auth.permission",
+ "delete": "'DELETE_UNI_ID_ROLES' in auth.permission"
+ },
+ "properties": {
+ "_id": {
+ "description": "存储文档 ID,系统自动生成"
+ },
+ "comment": {
+ "title": "备注",
+ "bsonType": "string",
+ "description": "备注",
+ "trim": "both"
+ },
+ "create_date": {
+ "bsonType": "timestamp",
+ "description": "创建时间",
+ "forceDefaultValue": {
+ "$env": "now"
+ }
+ },
+ "permission": {
+ "title": "权限",
+ "bsonType": "array",
+ "foreignKey": "uni-id-permissions.permission_id",
+ "description": "角色拥有的权限列表",
+ "enum": {
+ "collection": "uni-id-permissions",
+ "field": "permission_name as text, permission_id as value"
+ }
+ },
+ "role_id": {
+ "title": "唯一ID",
+ "bsonType": "string",
+ "description": "角色唯一标识,不可修改,不允许重复",
+ "trim": "both"
+ },
+ "role_name": {
+ "title": "名称",
+ "bsonType": "string",
+ "description": "角色名称",
+ "trim": "both"
+ }
+ }
+}
diff --git a/uni_modules/uni-id-pages/uniCloud/database/uni-id-users.schema.json b/uni_modules/uni-id-pages/uniCloud/database/uni-id-users.schema.json
new file mode 100644
index 0000000000000000000000000000000000000000..53cc584f1ae6823d49d021dd685e47a538a7d2ab
--- /dev/null
+++ b/uni_modules/uni-id-pages/uniCloud/database/uni-id-users.schema.json
@@ -0,0 +1,456 @@
+{
+ "bsonType": "object",
+ "permission": {
+ "read": true,
+ "create": "'CREATE_UNI_ID_USERS' in auth.permission",
+ "update": "doc._id == auth.uid || 'UPDATE_UNI_ID_USERS' in auth.permission",
+ "delete": "'DELETE_UNI_ID_USERS' in auth.permission"
+ },
+ "properties": {
+ "_id": {
+ "description": "存储文档 ID(用户 ID),系统自动生成"
+ },
+ "ali_openid": {
+ "bsonType": "string",
+ "description": "支付宝平台openid",
+ "permission": {
+ "read": "'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "apple_openid": {
+ "bsonType": "string",
+ "description": "苹果登录openid",
+ "permission": {
+ "read": "'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "avatar": {
+ "bsonType": "string",
+ "description": "头像地址",
+ "title": "头像地址",
+ "trim": "both",
+ "permission": {
+ "read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
+ "write": "doc._id == auth.uid || 'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "avatar_file": {
+ "bsonType": "file",
+ "description": "用file类型方便使用uni-file-picker组件",
+ "title": "头像文件",
+ "permission": {
+ "read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
+ "write": "doc._id == auth.uid || 'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "comment": {
+ "bsonType": "string",
+ "description": "备注",
+ "title": "备注",
+ "trim": "both",
+ "permission": {
+ "read": "'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "dcloud_appid": {
+ "bsonType": "array",
+ "description": "允许登录的客户端的appid列表",
+ "foreignKey": "opendb-app-list.appid",
+ "permission": {
+ "read": "'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "department_id": {
+ "bsonType": "array",
+ "description": "部门ID",
+ "enum": {
+ "collection": "opendb-department",
+ "field": "_id as value, name as text",
+ "orderby": "name asc"
+ },
+ "enumType": "tree",
+ "title": "部门",
+ "permission": {
+ "read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "email": {
+ "bsonType": "string",
+ "description": "邮箱地址",
+ "format": "email",
+ "title": "邮箱",
+ "trim": "both",
+ "permission": {
+ "read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "email_confirmed": {
+ "bsonType": "int",
+ "defaultValue": 0,
+ "description": "邮箱验证状态:0 未验证 1 已验证",
+ "enum": [{
+ "text": "未验证",
+ "value": 0
+ },
+ {
+ "text": "已验证",
+ "value": 1
+ }
+ ],
+ "title": "邮箱验证状态",
+ "permission": {
+ "read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "gender": {
+ "bsonType": "int",
+ "defaultValue": 0,
+ "description": "用户性别:0 未知 1 男性 2 女性",
+ "enum": [{
+ "text": "未知",
+ "value": 0
+ },
+ {
+ "text": "男",
+ "value": 1
+ },
+ {
+ "text": "女",
+ "value": 2
+ }
+ ],
+ "title": "性别",
+ "permission": {
+ "read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "invite_time": {
+ "bsonType": "timestamp",
+ "description": "受邀时间",
+ "permission": {
+ "read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "inviter_uid": {
+ "bsonType": "array",
+ "description": "用户全部上级邀请者",
+ "trim": "both",
+ "permission": {
+ "read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "last_login_date": {
+ "bsonType": "timestamp",
+ "description": "最后登录时间",
+ "permission": {
+ "read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "last_login_ip": {
+ "bsonType": "string",
+ "description": "最后登录时 IP 地址",
+ "permission": {
+ "read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "mobile": {
+ "bsonType": "string",
+ "description": "手机号码",
+ "pattern": "^\\+?[0-9-]{3,20}$",
+ "title": "手机号码",
+ "trim": "both",
+ "permission": {
+ "read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "mobile_confirmed": {
+ "bsonType": "int",
+ "defaultValue": 0,
+ "description": "手机号验证状态:0 未验证 1 已验证",
+ "enum": [{
+ "text": "未验证",
+ "value": 0
+ },
+ {
+ "text": "已验证",
+ "value": 1
+ }
+ ],
+ "title": "手机号验证状态",
+ "permission": {
+ "read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "my_invite_code": {
+ "bsonType": "string",
+ "description": "用户自身邀请码",
+ "permission": {
+ "read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "nickname": {
+ "bsonType": "string",
+ "description": "用户昵称",
+ "title": "昵称",
+ "trim": "both",
+ "permission": {
+ "read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
+ "write": "doc._id == auth.uid || 'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "password": {
+ "bsonType": "password",
+ "description": "密码,加密存储",
+ "title": "密码",
+ "trim": "both"
+ },
+ "password_secret_version": {
+ "bsonType": "int",
+ "description": "密码使用的passwordSecret版本",
+ "title": "passwordSecret",
+ "permission": {
+ "read": false,
+ "write": false
+ }
+ },
+ "realname_auth": {
+ "bsonType": "object",
+ "description": "实名认证信息",
+ "permission": {
+ "read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ },
+ "properties": {
+ "auth_date": {
+ "bsonType": "timestamp",
+ "description": "认证通过时间"
+ },
+ "auth_status": {
+ "bsonType": "int",
+ "description": "认证状态:0 未认证 1 等待认证 2 认证通过 3 认证失败",
+ "maximum": 3,
+ "minimum": 0
+ },
+ "contact_email": {
+ "bsonType": "string",
+ "description": "联系人邮箱"
+ },
+ "contact_mobile": {
+ "bsonType": "string",
+ "description": "联系人手机号码"
+ },
+ "contact_person": {
+ "bsonType": "string",
+ "description": "联系人姓名"
+ },
+ "id_card_back": {
+ "bsonType": "string",
+ "description": "身份证反面照 URL"
+ },
+ "id_card_front": {
+ "bsonType": "string",
+ "description": "身份证正面照 URL"
+ },
+ "identity": {
+ "bsonType": "string",
+ "description": "身份证号码/营业执照号码"
+ },
+ "in_hand": {
+ "bsonType": "string",
+ "description": "手持身份证照片 URL"
+ },
+ "license": {
+ "bsonType": "string",
+ "description": "营业执照 URL"
+ },
+ "real_name": {
+ "bsonType": "string",
+ "description": "真实姓名/企业名称"
+ },
+ "type": {
+ "bsonType": "int",
+ "description": "用户类型:0 个人用户 1 企业用户",
+ "maximum": 1,
+ "minimum": 0
+ }
+ },
+ "required": [
+ "type",
+ "auth_status"
+ ]
+ },
+ "register_date": {
+ "bsonType": "timestamp",
+ "description": "注册时间",
+ "forceDefaultValue": {
+ "$env": "now"
+ },
+ "permission": {
+ "read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "register_ip": {
+ "bsonType": "string",
+ "description": "注册时 IP 地址",
+ "forceDefaultValue": {
+ "$env": "clientIP"
+ },
+ "permission": {
+ "read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "role": {
+ "bsonType": "array",
+ "description": "用户角色",
+ "enum": {
+ "collection": "uni-id-roles",
+ "field": "role_id as value, role_name as text"
+ },
+ "foreignKey": "uni-id-roles.role_id",
+ "permission": {
+ "read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ },
+ "title": "角色"
+ },
+ "score": {
+ "bsonType": "int",
+ "description": "用户积分,积分变更记录可参考:uni-id-scores表定义",
+ "permission": {
+ "read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "status": {
+ "bsonType": "int",
+ "defaultValue": 0,
+ "description": "用户状态:0 正常 1 禁用 2 审核中 3 审核拒绝",
+ "permission": {
+ "read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ },
+ "enum": [{
+ "text": "正常",
+ "value": 0
+ },
+ {
+ "text": "禁用",
+ "value": 1
+ },
+ {
+ "text": "审核中",
+ "value": 2
+ },
+ {
+ "text": "审核拒绝",
+ "value": 3
+ }
+ ],
+ "title": "用户状态"
+ },
+ "token": {
+ "bsonType": "array",
+ "description": "用户token",
+ "permission": {
+ "read": "'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "username": {
+ "bsonType": "string",
+ "description": "用户名,不允许重复",
+ "title": "用户名",
+ "trim": "both",
+ "permission": {
+ "read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "wx_openid": {
+ "bsonType": "object",
+ "description": "微信各个平台openid",
+ "properties": {
+ "app": {
+ "bsonType": "string",
+ "description": "app平台微信openid"
+ },
+ "mp": {
+ "bsonType": "string",
+ "description": "微信小程序平台openid"
+ },
+ "h5": {
+ "bsonType": "string",
+ "description": "微信公众号登录openid"
+ },
+ "web": {
+ "bsonType": "string",
+ "description": "PC页面扫码登录openid"
+ }
+ },
+ "permission": {
+ "read": "'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "wx_unionid": {
+ "bsonType": "string",
+ "description": "微信unionid",
+ "permission": {
+ "read": "'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "qq_openid": {
+ "bsonType": "object",
+ "description": "QQ各个平台openid",
+ "properties": {
+ "app": {
+ "bsonType": "string",
+ "description": "app平台QQ openid"
+ },
+ "mp": {
+ "bsonType": "string",
+ "description": "QQ小程序平台openid"
+ }
+ },
+ "permission": {
+ "read": "'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "qq_unionid": {
+ "bsonType": "string",
+ "description": "QQ unionid",
+ "permission": {
+ "read": "'READ_UNI_ID_USERS' in auth.permission",
+ "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
+ }
+ },
+ "third_party": {
+ "bsonType": "object",
+ "description": "三方平台凭证",
+ "permission": {
+ "read": false,
+ "write": false
+ }
+ }
+ },
+ "required": []
+}
\ No newline at end of file
diff --git a/uni_modules/uni-open-bridge-common/changelog.md b/uni_modules/uni-open-bridge-common/changelog.md
new file mode 100644
index 0000000000000000000000000000000000000000..b3a56b2159cc6e557d1243e46697f51228469203
--- /dev/null
+++ b/uni_modules/uni-open-bridge-common/changelog.md
@@ -0,0 +1,8 @@
+## 1.0.4(2022-09-21)
+- 新增 支持使用阿里云固定IP获取微信公众号H5凭据 access_token、ticket,开发者需要在微信公众平台配置阿里云固定IP,[固定IP详情](https://uniapp.dcloud.net.cn/uniCloud/cf-functions.html#aliyun-eip)
+## 1.0.3(2022-09-06)
+- 修复 过期时间问题,容错 AccessToken 默认 fallback 逻辑,当微信服务器没有返回过期时间时设置为2小时后过期
+## 1.0.2(2022-09-02)
+- 新增 依赖数据表schema opendb-open-data
+## 1.0.0(2022-08-22)
+- 首次发布
diff --git a/uni_modules/uni-open-bridge-common/package.json b/uni_modules/uni-open-bridge-common/package.json
new file mode 100644
index 0000000000000000000000000000000000000000..487f353036fb429fae776b437f875e6651b024aa
--- /dev/null
+++ b/uni_modules/uni-open-bridge-common/package.json
@@ -0,0 +1,84 @@
+{
+ "id": "uni-open-bridge-common",
+ "displayName": "uni-open-bridge-common",
+ "version": "1.0.4",
+ "description": "统一接管微信等三方平台认证凭据",
+ "keywords": [
+ "uni-open-bridge-common",
+ "access_token",
+ "session_key",
+ "ticket"
+],
+ "repository": "",
+ "engines": {
+ "HBuilderX": "^3.5.2"
+ },
+ "dcloudext": {
+ "type": "unicloud-template-function",
+ "sale": {
+ "regular": {
+ "price": "0.00"
+ },
+ "sourcecode": {
+ "price": "0.00"
+ }
+ },
+ "contact": {
+ "qq": ""
+ },
+ "declaration": {
+ "ads": "无",
+ "data": "无",
+ "permissions": "无"
+ },
+ "npmurl": ""
+ },
+ "uni_modules": {
+ "dependencies": [],
+ "encrypt": [],
+ "platforms": {
+ "cloud": {
+ "tcb": "y",
+ "aliyun": "y"
+ },
+ "client": {
+ "Vue": {
+ "vue2": "u",
+ "vue3": "u"
+ },
+ "App": {
+ "app-vue": "u",
+ "app-nvue": "u"
+ },
+ "H5-mobile": {
+ "Safari": "u",
+ "Android Browser": "u",
+ "微信浏览器(Android)": "u",
+ "QQ浏览器(Android)": "u"
+ },
+ "H5-pc": {
+ "Chrome": "u",
+ "IE": "u",
+ "Edge": "u",
+ "Firefox": "u",
+ "Safari": "u"
+ },
+ "小程序": {
+ "微信": "u",
+ "阿里": "u",
+ "百度": "u",
+ "字节跳动": "u",
+ "QQ": "u",
+ "钉钉": "u",
+ "快手": "u",
+ "飞书": "u",
+ "京东": "u"
+ },
+ "快应用": {
+ "华为": "u",
+ "联盟": "u"
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/uni_modules/uni-open-bridge-common/readme.md b/uni_modules/uni-open-bridge-common/readme.md
new file mode 100644
index 0000000000000000000000000000000000000000..3892384764fe33d38c9ae74fc2b5deca7b850898
--- /dev/null
+++ b/uni_modules/uni-open-bridge-common/readme.md
@@ -0,0 +1,5 @@
+# uni-open-bridge-common
+
+`uni-open-bridge-common` 是统一接管微信等三方平台认证凭据(包括但不限于`access_token`、`session_key`、`encrypt_key`、`ticket`)的开源库。
+
+文档链接 [https://uniapp.dcloud.net.cn/uniCloud/uni-open-bridge#common](https://uniapp.dcloud.net.cn/uniCloud/uni-open-bridge#common)
diff --git a/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/bridge-error.js b/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/bridge-error.js
new file mode 100644
index 0000000000000000000000000000000000000000..95160a4390ade5693feaf7aa226a7d9d13765db1
--- /dev/null
+++ b/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/bridge-error.js
@@ -0,0 +1,26 @@
+'use strict';
+
+class BridgeError extends Error {
+
+ constructor(code, message) {
+ super(message)
+
+ this._code = code
+ }
+
+ get code() {
+ return this._code
+ }
+
+ get errCode() {
+ return this._code
+ }
+
+ get errMsg() {
+ return this.message
+ }
+}
+
+module.exports = {
+ BridgeError
+}
diff --git a/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/config.js b/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/config.js
new file mode 100644
index 0000000000000000000000000000000000000000..2fb7d7b050baa9e6af2b38af9fe8725c311a7aed
--- /dev/null
+++ b/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/config.js
@@ -0,0 +1,95 @@
+'use strict';
+
+const {
+ PlatformType
+} = require('./consts.js')
+
+const configCenter = require('uni-config-center')
+
+const OauthConfig = {
+ 'weixin-mp': ['mp-weixin', 'oauth', 'weixin'],
+ 'weixin-h5': ['web', 'oauth', 'weixin-h5']
+}
+
+class ConfigBase {
+
+ constructor() {
+ this._ready = false
+ this._uniId = null
+
+ const uniIdConfig = configCenter({
+ pluginId: 'uni-id'
+ })
+
+ this._uniId = uniIdConfig.config()
+
+ this._ready = true
+ }
+
+ getAppConfig(appid) {
+ if (Array.isArray(this._uniId)) {
+ return this._uniId.find((item) => {
+ return (item.dcloudAppid === appid)
+ })
+ }
+ return this._uniId
+ }
+
+ get ready() {
+ return this._ready
+ }
+}
+
+class AppConfig extends ConfigBase {
+
+ constructor() {
+ super()
+ }
+
+ get(appid, platform) {
+ if (!this.isSupport(platform)) {
+ return null
+ }
+
+ let appConfig = this.getAppConfig(appid)
+ if (!appConfig) {
+ return null
+ }
+
+ return this.getOauthConfig(appConfig, platform)
+ }
+
+ isSupport(platformName) {
+ return (AppConfig.Support_Platforms.indexOf(platformName) >= 0)
+ }
+
+ getOauthConfig(appConfig, platformName) {
+ let tree = OauthConfig[platformName]
+ let node = appConfig
+ for (let i = 0; i < tree.length; i++) {
+ let nodeName = tree[i]
+ if (node[nodeName]) {
+ node = node[nodeName]
+ } else {
+ node = null
+ break
+ }
+ }
+
+ if (node && node.appid && node.appsecret) {
+ return {
+ appid: node.appid,
+ secret: node.appsecret
+ }
+ }
+
+ return null
+ }
+}
+
+AppConfig.Support_Platforms = [PlatformType.WEIXIN_MP, PlatformType.WEIXIN_H5]
+
+
+module.exports = {
+ AppConfig
+};
diff --git a/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/consts.js b/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/consts.js
new file mode 100644
index 0000000000000000000000000000000000000000..6da817b9620336453e06025815a12d378249ebde
--- /dev/null
+++ b/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/consts.js
@@ -0,0 +1,26 @@
+'use strict';
+
+const TAG = "UNI_OPEN_BRIDGE"
+
+const HTTP_STATUS = {
+ SUCCESS: 200
+}
+
+const PlatformType = {
+ WEIXIN_MP: 'weixin-mp',
+ WEIXIN_H5: 'weixin-h5',
+ WEIXIN_APP: 'weixin-app',
+ WEIXIN_WEB: 'weixin-web',
+ QQ_MP: 'qq-mp',
+ QQ_APP: 'qq-app'
+}
+
+const ErrorCodeType = {
+ SYSTEM_ERROR: TAG + "_SYSTEM_ERROR"
+}
+
+module.exports = {
+ HTTP_STATUS,
+ PlatformType,
+ ErrorCodeType
+}
diff --git a/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/index.js b/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/index.js
new file mode 100644
index 0000000000000000000000000000000000000000..f39b0af531b251a208a03b3b6c108a65935057a1
--- /dev/null
+++ b/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/index.js
@@ -0,0 +1,221 @@
+'use strict';
+
+const {
+ PlatformType,
+ ErrorCodeType
+} = require('./consts.js')
+
+const {
+ AppConfig
+} = require('./config.js')
+
+const {
+ Storage,
+ Factory
+} = require('./storage.js')
+
+const {
+ BridgeError
+} = require('./bridge-error.js')
+
+const {
+ WeixinServer
+} = require('./weixin-server.js')
+
+const appConfig = new AppConfig()
+
+class AccessToken extends Storage {
+
+ constructor() {
+ super('access-token', ['dcloudAppid', 'platform'])
+ }
+
+ async fallback(parameters) {
+ const oauthConfig = appConfig.get(parameters.dcloudAppid, parameters.platform)
+ let methodName
+ if (parameters.platform === PlatformType.WEIXIN_MP) {
+ methodName = 'GetMPAccessTokenData'
+ } else if (parameters.platform === PlatformType.WEIXIN_H5) {
+ methodName = 'GetH5AccessTokenData'
+ } else {
+ throw new BridgeError(ErrorCodeType.SYSTEM_ERROR, "platform invalid")
+ }
+
+ const responseData = await WeixinServer[methodName](oauthConfig)
+
+ const duration = responseData.expires_in || (60 * 60 * 2)
+ delete responseData.expires_in
+
+ return {
+ value: responseData,
+ duration
+ }
+ }
+}
+
+class UserAccessToken extends Storage {
+
+ constructor() {
+ super('user-access-token', ['dcloudAppid', 'platform', 'openid'])
+ }
+}
+
+class SessionKey extends Storage {
+
+ constructor() {
+ super('session-key', ['dcloudAppid', 'platform', 'openid'])
+ }
+}
+
+class Encryptkey extends Storage {
+
+ constructor() {
+ super('encrypt-key', ['dcloudAppid', 'platform', 'openid'])
+ }
+
+ getKeyString(key) {
+ return `${super.getKeyString(key)}-${key.version}`
+ }
+
+ getExpiresIn(value) {
+ if (value <= 0) {
+ return 60
+ }
+ return value
+ }
+
+ async fallback(parameters) {
+ const accessToken = await Factory.Get(AccessToken, parameters)
+ const userSession = await Factory.Get(SessionKey, parameters)
+
+ const responseData = await WeixinServer.GetUserEncryptKeyData({
+ openid: parameters.openid,
+ access_token: accessToken.access_token,
+ session_key: userSession.session_key
+ })
+
+ const keyInfo = responseData.key_info_list.find((item) => {
+ return item.version = parameters.version
+ })
+
+ const value = {
+ encrypt_key: keyInfo.encrypt_key,
+ iv: keyInfo.iv
+ }
+
+ return {
+ value,
+ duration: keyInfo.expire_in
+ }
+ }
+}
+
+class Ticket extends Storage {
+
+ constructor() {
+ super('ticket', ['dcloudAppid', 'platform'])
+ }
+
+ async fallback(parameters) {
+ const accessToken = await Factory.Get(AccessToken, {
+ dcloudAppid: parameters.dcloudAppid,
+ platform: PlatformType.WEIXIN_H5
+ })
+
+ const responseData = await WeixinServer.GetH5TicketData(accessToken)
+
+ const duration = responseData.expires_in || (60 * 60 * 2)
+ delete responseData.expires_in
+ delete responseData.errcode
+ delete responseData.errmsg
+
+ return {
+ value: responseData,
+ duration
+ }
+ }
+}
+
+
+// exports
+
+async function getAccessToken(key, fallback) {
+ return await Factory.Get(AccessToken, key, fallback)
+}
+
+async function setAccessToken(key, value, expiresIn) {
+ await Factory.Set(AccessToken, key, value, expiresIn)
+}
+
+async function removeAccessToken(key) {
+ await Factory.Remove(AccessToken, key)
+}
+
+async function getUserAccessToken(key, fallback) {
+ return await Factory.Get(UserAccessToken, key, fallback)
+}
+
+async function setUserAccessToken(key, value, expiresIn) {
+ await Factory.Set(UserAccessToken, key, value, expiresIn)
+}
+
+async function removeUserAccessToken(key) {
+ await Factory.Remove(UserAccessToken, key)
+}
+
+async function getSessionKey(key, fallback) {
+ return await Factory.Get(SessionKey, key, fallback)
+}
+
+async function setSessionKey(key, value, expiresIn) {
+ await Factory.Set(SessionKey, key, value, expiresIn)
+}
+
+async function removeSessionKey(key) {
+ await Factory.Remove(SessionKey, key)
+}
+
+async function getEncryptKey(key, fallback) {
+ return await Factory.Get(Encryptkey, key, fallback)
+}
+
+async function setEncryptKey(key, value, expiresIn) {
+ await Factory.Set(Encryptkey, key, value, expiresIn)
+}
+
+async function removeEncryptKey(key) {
+ await Factory.Remove(Encryptkey, key)
+}
+
+async function getTicket(key, fallback) {
+ return await Factory.Get(Ticket, key, fallback)
+}
+
+async function setTicket(key, value, expiresIn) {
+ await Factory.Set(Ticket, key, value, expiresIn)
+}
+
+async function removeTicket(key) {
+ await Factory.Remove(Ticket, key)
+}
+
+module.exports = {
+ getAccessToken,
+ setAccessToken,
+ removeAccessToken,
+ getUserAccessToken,
+ setUserAccessToken,
+ removeUserAccessToken,
+ getSessionKey,
+ setSessionKey,
+ removeSessionKey,
+ getEncryptKey,
+ setEncryptKey,
+ removeEncryptKey,
+ getTicket,
+ setTicket,
+ removeTicket,
+ PlatformType,
+ WeixinServer,
+ ErrorCodeType
+}
diff --git a/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/node_modules/uni-config-center/index.js b/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/node_modules/uni-config-center/index.js
new file mode 100644
index 0000000000000000000000000000000000000000..e14fb3b0a213443d5c51cb3fcb763d322c21c97f
--- /dev/null
+++ b/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/node_modules/uni-config-center/index.js
@@ -0,0 +1 @@
+"use strict";var t=require("fs"),r=require("path");function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=e(t),o=e(r),i="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var u=function(t){var r={exports:{}};return t(r,r.exports),r.exports}((function(t,r){var e="__lodash_hash_undefined__",n=9007199254740991,o="[object Arguments]",u="[object Function]",c="[object Object]",a=/^\[object .+?Constructor\]$/,f=/^(?:0|[1-9]\d*)$/,s={};s["[object Float32Array]"]=s["[object Float64Array]"]=s["[object Int8Array]"]=s["[object Int16Array]"]=s["[object Int32Array]"]=s["[object Uint8Array]"]=s["[object Uint8ClampedArray]"]=s["[object Uint16Array]"]=s["[object Uint32Array]"]=!0,s[o]=s["[object Array]"]=s["[object ArrayBuffer]"]=s["[object Boolean]"]=s["[object DataView]"]=s["[object Date]"]=s["[object Error]"]=s[u]=s["[object Map]"]=s["[object Number]"]=s[c]=s["[object RegExp]"]=s["[object Set]"]=s["[object String]"]=s["[object WeakMap]"]=!1;var l="object"==typeof i&&i&&i.Object===Object&&i,h="object"==typeof self&&self&&self.Object===Object&&self,p=l||h||Function("return this")(),_=r&&!r.nodeType&&r,v=_&&t&&!t.nodeType&&t,d=v&&v.exports===_,y=d&&l.process,g=function(){try{var t=v&&v.require&&v.require("util").types;return t||y&&y.binding&&y.binding("util")}catch(t){}}(),b=g&&g.isTypedArray;function j(t,r,e){switch(e.length){case 0:return t.call(r);case 1:return t.call(r,e[0]);case 2:return t.call(r,e[0],e[1]);case 3:return t.call(r,e[0],e[1],e[2])}return t.apply(r,e)}var w,O,m,A=Array.prototype,z=Function.prototype,M=Object.prototype,x=p["__core-js_shared__"],C=z.toString,F=M.hasOwnProperty,U=(w=/[^.]+$/.exec(x&&x.keys&&x.keys.IE_PROTO||""))?"Symbol(src)_1."+w:"",S=M.toString,I=C.call(Object),P=RegExp("^"+C.call(F).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),T=d?p.Buffer:void 0,q=p.Symbol,E=p.Uint8Array,$=T?T.allocUnsafe:void 0,D=(O=Object.getPrototypeOf,m=Object,function(t){return O(m(t))}),k=Object.create,B=M.propertyIsEnumerable,N=A.splice,L=q?q.toStringTag:void 0,R=function(){try{var t=_t(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),G=T?T.isBuffer:void 0,V=Math.max,W=Date.now,H=_t(p,"Map"),J=_t(Object,"create"),K=function(){function t(){}return function(r){if(!Mt(r))return{};if(k)return k(r);t.prototype=r;var e=new t;return t.prototype=void 0,e}}();function Q(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r-1},X.prototype.set=function(t,r){var e=this.__data__,n=nt(e,t);return n<0?(++this.size,e.push([t,r])):e[n][1]=r,this},Y.prototype.clear=function(){this.size=0,this.__data__={hash:new Q,map:new(H||X),string:new Q}},Y.prototype.delete=function(t){var r=pt(this,t).delete(t);return this.size-=r?1:0,r},Y.prototype.get=function(t){return pt(this,t).get(t)},Y.prototype.has=function(t){return pt(this,t).has(t)},Y.prototype.set=function(t,r){var e=pt(this,t),n=e.size;return e.set(t,r),this.size+=e.size==n?0:1,this},Z.prototype.clear=function(){this.__data__=new X,this.size=0},Z.prototype.delete=function(t){var r=this.__data__,e=r.delete(t);return this.size=r.size,e},Z.prototype.get=function(t){return this.__data__.get(t)},Z.prototype.has=function(t){return this.__data__.has(t)},Z.prototype.set=function(t,r){var e=this.__data__;if(e instanceof X){var n=e.__data__;if(!H||n.length<199)return n.push([t,r]),this.size=++e.size,this;e=this.__data__=new Y(n)}return e.set(t,r),this.size=e.size,this};var it,ut=function(t,r,e){for(var n=-1,o=Object(t),i=e(t),u=i.length;u--;){var c=i[it?u:++n];if(!1===r(o[c],c,o))break}return t};function ct(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":L&&L in Object(t)?function(t){var r=F.call(t,L),e=t[L];try{t[L]=void 0;var n=!0}catch(t){}var o=S.call(t);n&&(r?t[L]=e:delete t[L]);return o}(t):function(t){return S.call(t)}(t)}function at(t){return xt(t)&&ct(t)==o}function ft(t){return!(!Mt(t)||function(t){return!!U&&U in t}(t))&&(At(t)?P:a).test(function(t){if(null!=t){try{return C.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function st(t){if(!Mt(t))return function(t){var r=[];if(null!=t)for(var e in Object(t))r.push(e);return r}(t);var r=dt(t),e=[];for(var n in t)("constructor"!=n||!r&&F.call(t,n))&&e.push(n);return e}function lt(t,r,e,n,o){t!==r&&ut(r,(function(i,u){if(o||(o=new Z),Mt(i))!function(t,r,e,n,o,i,u){var a=yt(t,e),f=yt(r,e),s=u.get(f);if(s)return void rt(t,e,s);var l=i?i(a,f,e+"",t,r,u):void 0,h=void 0===l;if(h){var p=wt(f),_=!p&&mt(f),v=!p&&!_&&Ct(f);l=f,p||_||v?wt(a)?l=a:xt(j=a)&&Ot(j)?l=function(t,r){var e=-1,n=t.length;r||(r=Array(n));for(;++e-1&&t%1==0&&t0){if(++r>=800)return arguments[0]}else r=0;return t.apply(void 0,arguments)}}(R?function(t,r){return R(t,"toString",{configurable:!0,enumerable:!1,value:(e=r,function(){return e}),writable:!0});var e}:It);function bt(t,r){return t===r||t!=t&&r!=r}var jt=at(function(){return arguments}())?at:function(t){return xt(t)&&F.call(t,"callee")&&!B.call(t,"callee")},wt=Array.isArray;function Ot(t){return null!=t&&zt(t.length)&&!At(t)}var mt=G||function(){return!1};function At(t){if(!Mt(t))return!1;var r=ct(t);return r==u||"[object GeneratorFunction]"==r||"[object AsyncFunction]"==r||"[object Proxy]"==r}function zt(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=n}function Mt(t){var r=typeof t;return null!=t&&("object"==r||"function"==r)}function xt(t){return null!=t&&"object"==typeof t}var Ct=b?function(t){return function(r){return t(r)}}(b):function(t){return xt(t)&&zt(t.length)&&!!s[ct(t)]};function Ft(t){return Ot(t)?tt(t,!0):st(t)}var Ut,St=(Ut=function(t,r,e){lt(t,r,e)},ht((function(t,r){var e=-1,n=r.length,o=n>1?r[n-1]:void 0,i=n>2?r[2]:void 0;for(o=Ut.length>3&&"function"==typeof o?(n--,o):void 0,i&&function(t,r,e){if(!Mt(e))return!1;var n=typeof r;return!!("number"==n?Ot(e)&&vt(r,e.length):"string"==n&&r in e)&&bt(e[r],t)}(r[0],r[1],i)&&(o=n<3?void 0:o,n=1),t=Object(t);++ec.call(t,r);class f{constructor({pluginId:t,defaultConfig:r={},customMerge:e,root:n}){this.pluginId=t,this.defaultConfig=r,this.pluginConfigPath=o.default.resolve(n||__dirname,t),this.customMerge=e,this._config=void 0}resolve(t){return o.default.resolve(this.pluginConfigPath,t)}hasFile(t){return n.default.existsSync(this.resolve(t))}requireFile(t){try{return require(this.resolve(t))}catch(t){if("MODULE_NOT_FOUND"===t.code)return;throw t}}_getUserConfig(){return this.requireFile("config.json")}config(t,r){this._config||(this._config=(this.customMerge||u)(this.defaultConfig,this._getUserConfig()));let e=this._config;return t?function(t,r,e){if("number"==typeof r)return t[r];if("symbol"==typeof r)return a(t,r)?t[r]:e;const n="string"!=typeof(o=r)?o:o.split(".").reduce(((t,r)=>(r.split(/\[([^}]+)\]/g).forEach((r=>r&&t.push(r))),t)),[]);var o;let i=t;for(let t=0;t {
+ keyArray.push(key[name])
+ })
+ keyArray.push(this._type)
+ return keyArray.join(':')
+ }
+
+ getValue(value) {
+ return value
+ }
+
+ getExpiresIn(value) {
+ if (value !== undefined) {
+ return value
+ }
+ return -1
+ }
+
+ validateKey(key) {
+ Validator.Key(this._keys, key)
+ }
+
+ validateValue(value) {
+ Validator.Value(value)
+ }
+
+ create(key, fallback) {
+ const keyString = this.getKeyString(key)
+ const options = {
+ layers: [{
+ type: 'database',
+ key: keyString
+ }, {
+ type: 'redis',
+ key: keyString
+ }]
+ }
+ if (fallback !== null) {
+ const fallbackFunction = fallback || this.fallback
+ if (fallbackFunction) {
+ options.fallback = async () => {
+ return await fallbackFunction(key)
+ }
+ }
+ }
+ return new CacheKeyCascade(options)
+ }
+}
+Storage.Prefix = "uni-id"
+
+const Factory = {
+
+ async Get(T, key, fallback) {
+ return await Factory.MakeUnique(T).get(key, fallback)
+ },
+
+ async Set(T, key, value, expiresIn) {
+ await Factory.MakeUnique(T).set(key, value, expiresIn)
+ },
+
+ async Remove(T, key) {
+ await Factory.MakeUnique(T).remove(key)
+ },
+
+ MakeUnique(T) {
+ return new T()
+ }
+}
+
+module.exports = {
+ Storage,
+ Factory
+};
diff --git a/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/uni-cloud-cache.js b/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/uni-cloud-cache.js
new file mode 100644
index 0000000000000000000000000000000000000000..2e4286be42be9f447b22f199e70e670af9416db4
--- /dev/null
+++ b/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/uni-cloud-cache.js
@@ -0,0 +1,324 @@
+const db = uniCloud.database()
+
+function getType(value) {
+ return Object.prototype.toString.call(value).slice(8, -1).toLowerCase()
+}
+
+const validator = {
+ key: function(value) {
+ const err = new Error('Invalid key')
+ if (typeof value !== 'string') {
+ throw err
+ }
+ const valueTrim = value.trim()
+ if (!valueTrim || valueTrim !== value) {
+ throw err
+ }
+ },
+ value: function(value) {
+ // 仅作简单校验
+ const type = getType(value)
+ const validValueType = ['null', 'number', 'string', 'array', 'object']
+ if (validValueType.indexOf(type) === -1) {
+ throw new Error('Invalid value type')
+ }
+ },
+ duration: function(value) {
+ const err = new Error('Invalid duration')
+ if (value === undefined) {
+ return
+ }
+ if (typeof value !== 'number' || value === 0) {
+ throw err
+ }
+ }
+}
+
+/**
+ * 入库时 expired 为过期时间对应的时间戳,永不过期用-1表示
+ * 返回结果时 与redis对齐,-1表示永不过期,-2表示已过期或不存在
+ */
+class DatabaseCache {
+ constructor({
+ collection = 'opendb-open-data'
+ } = {}) {
+ this.type = 'db'
+ this.collection = db.collection(collection)
+ }
+
+ _serializeValue(value) {
+ return value === undefined ? null : JSON.stringify(value)
+ }
+
+ _deserializeValue(value) {
+ return value ? JSON.parse(value) : value
+ }
+
+ async set(key, value, duration) {
+ validator.key(key)
+ validator.value(value)
+ validator.duration(duration)
+ value = this._serializeValue(value)
+ await this.collection.doc(key).set({
+ value,
+ expired: duration && duration !== -1 ? Date.now() + (duration * 1000) : -1
+ })
+ }
+
+ async _getWithDuration(key) {
+ const getKeyRes = await this.collection.doc(key).get()
+ const record = getKeyRes.data[0]
+ if (!record) {
+ return {
+ value: null,
+ duration: -2
+ }
+ }
+ const value = this._deserializeValue(record.value)
+ const expired = record.expired
+ if (expired === -1) {
+ return {
+ value,
+ duration: -1
+ }
+ }
+ const duration = expired - Date.now()
+ if (duration <= 0) {
+ await this.remove(key)
+ return {
+ value: null,
+ duration: -2
+ }
+ }
+ return {
+ value,
+ duration: Math.floor(duration / 1000)
+ }
+ }
+
+ async get(key, {
+ withDuration = true
+ } = {}) {
+ const result = await this._getWithDuration(key)
+ if (!withDuration) {
+ delete result.duration
+ }
+ return result
+ }
+
+ async remove(key) {
+ await this.collection.doc(key).remove()
+ }
+}
+
+class RedisCache {
+ constructor() {
+ this.type = 'redis'
+ this.redis = uniCloud.redis()
+ }
+
+ _serializeValue(value) {
+ return value === undefined ? null : JSON.stringify(value)
+ }
+
+ _deserializeValue(value) {
+ return value ? JSON.parse(value) : value
+ }
+
+ async set(key, value, duration) {
+ validator.key(key)
+ validator.value(value)
+ validator.duration(duration)
+ value = this._serializeValue(value)
+ if (!duration || duration === -1) {
+ await this.redis.set(key, value)
+ } else {
+ await this.redis.set(key, value, 'EX', duration)
+ }
+ }
+
+ async get(key, {
+ withDuration = false
+ } = {}) {
+ let value = await this.redis.get(key)
+ value = this._deserializeValue(value)
+ if (!withDuration) {
+ return {
+ value
+ }
+ }
+ const durationSecond = await this.redis.ttl(key)
+ let duration
+ switch (durationSecond) {
+ case -1:
+ duration = -1
+ break
+ case -2:
+ duration = -2
+ break
+ default:
+ duration = durationSecond
+ break
+ }
+ return {
+ value,
+ duration
+ }
+ }
+
+ async remove(key) {
+ await this.redis.del(key)
+ }
+}
+
+class Cache {
+ constructor({
+ type,
+ collection
+ } = {}) {
+ if (type === 'database') {
+ return new DatabaseCache({
+ collection
+ })
+ } else if (type === 'redis') {
+ return new RedisCache()
+ } else {
+ throw new Error('Invalid cache type')
+ }
+ }
+}
+
+class CacheKey {
+ constructor({
+ type,
+ collection,
+ cache,
+ key,
+ fallback
+ } = {}) {
+ this.cache = cache || new Cache({
+ type,
+ collection
+ })
+ this.key = key
+ this.fallback = fallback
+ }
+
+ async set(value, duration) {
+ await this.cache.set(this.key, value, duration)
+ }
+
+ async setWithSync(value, duration, syncMethod) {
+ await Promise.all([
+ this.set(this.key, value, duration),
+ syncMethod(value, duration)
+ ])
+ }
+
+ async get() {
+ let {
+ value,
+ duration
+ } = await this.cache.get(this.key)
+ if (value !== null && value !== undefined) {
+ return {
+ value,
+ duration
+ }
+ }
+ if (!this.fallback) {
+ return {
+ value: null,
+ duration: -2
+ }
+ }
+ const fallbackResult = await this.fallback()
+ value = fallbackResult.value
+ duration = fallbackResult.duration
+ if (value !== null && duration !== undefined) {
+ await this.cache.set(this.key, value, duration)
+ }
+ return {
+ value,
+ duration
+ }
+ }
+
+ async remove() {
+ await this.cache.remove(this.key)
+ }
+}
+
+class CacheKeyCascade {
+ constructor({
+ layers, // [{cache, type, collection, key}] 从低级到高级排序,[DbCacheKey, RedisCacheKey]
+ fallback
+ } = {}) {
+ this.layers = layers
+ this.cacheLayers = []
+ let lastCacheKey
+ for (let i = 0; i < layers.length; i++) {
+ const {
+ type,
+ cache,
+ collection,
+ key
+ } = layers[i]
+ const lastCacheKeyTemp = lastCacheKey
+ try {
+ const currentCacheKey = new CacheKey({
+ type,
+ collection,
+ cache,
+ key,
+ fallback: i === 0 ? fallback : function() {
+ return lastCacheKeyTemp.get()
+ }
+ })
+ this.cacheLayers.push(currentCacheKey)
+ lastCacheKey = currentCacheKey
+ } catch (e) {}
+ }
+ this.highLevelCache = lastCacheKey
+ }
+
+ async set(value, duration) {
+ return Promise.all(
+ this.cacheLayers.map(item => {
+ return item.set(value, duration)
+ })
+ )
+ }
+
+ async setWithSync(value, duration, syncMethod) {
+ const setPromise = this.cacheLayers.map(item => {
+ return item.set(value, duration)
+ })
+ return Promise.all(
+ [
+ ...setPromise,
+ syncMethod(value, duration)
+ ]
+ )
+ }
+
+ async get() {
+ return this.highLevelCache.get()
+ }
+
+ async remove() {
+ await Promise.all(
+ this.cacheLayers.map(cacheKeyItem => {
+ return cacheKeyItem.remove()
+ })
+ )
+ }
+}
+
+module.exports = {
+ Cache,
+ DatabaseCache,
+ RedisCache,
+ CacheKey,
+ CacheKeyCascade
+}
diff --git a/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/validator.js b/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/validator.js
new file mode 100644
index 0000000000000000000000000000000000000000..47a455b15a479ce608838731287f5776985e191c
--- /dev/null
+++ b/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/validator.js
@@ -0,0 +1,31 @@
+const Validator = {
+
+ Key(keyArray, parameters) {
+ for (let i = 0; i < keyArray.length; i++) {
+ const keyName = keyArray[i]
+ if (typeof parameters[keyName] !== 'string') {
+ Validator.ThrowNewError(`Invalid ${keyName}`)
+ }
+ if (parameters[keyName].length < 1) {
+ Validator.ThrowNewError(`Invalid ${keyName}`)
+ }
+ }
+ },
+
+ Value(value) {
+ if (value === undefined) {
+ Validator.ThrowNewError('Invalid Value')
+ }
+ if (typeof value !== 'object') {
+ Validator.ThrowNewError('Invalid Value Type')
+ }
+ },
+
+ ThrowNewError(message) {
+ throw new Error(message)
+ }
+}
+
+module.exports = {
+ Validator
+}
diff --git a/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/weixin-server.js b/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/weixin-server.js
new file mode 100644
index 0000000000000000000000000000000000000000..0a0c811338d5c7d83f816c71d1189cd29e16ffd2
--- /dev/null
+++ b/uni_modules/uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common/weixin-server.js
@@ -0,0 +1,202 @@
+'use strict';
+
+const crypto = require('crypto')
+
+const {
+ HTTP_STATUS
+} = require('./consts.js')
+
+const {
+ BridgeError
+} = require('./bridge-error.js')
+
+class WeixinServer {
+
+ constructor(options = {}) {
+ this._appid = options.appid
+ this._secret = options.secret
+ }
+
+ getAccessToken() {
+ return uniCloud.httpclient.request(WeixinServer.AccessToken_Url, {
+ dataType: 'json',
+ method: 'POST',
+ data: {
+ appid: this._appid,
+ secret: this._secret,
+ grant_type: "client_credential"
+ }
+ })
+ }
+
+ // 使用客户端获取的 code 从微信服务器换取 openid,code 仅可使用一次
+ codeToSession(code) {
+ return uniCloud.httpclient.request(WeixinServer.Code2Session_Url, {
+ dataType: 'json',
+ data: {
+ appid: this._appid,
+ secret: this._secret,
+ js_code: code,
+ grant_type: 'authorization_code'
+ }
+ })
+ }
+
+ getUserEncryptKey({
+ access_token,
+ openid,
+ session_key
+ }) {
+ console.log(access_token, openid, session_key);
+ const signature = crypto.createHmac('sha256', session_key).update('').digest('hex')
+ return uniCloud.httpclient.request(WeixinServer.User_Encrypt_Key_Url, {
+ dataType: 'json',
+ method: 'POST',
+ dataAsQueryString: true,
+ data: {
+ access_token,
+ openid: openid,
+ signature: signature,
+ sig_method: 'hmac_sha256'
+ }
+ })
+ }
+
+ getH5AccessToken() {
+ return uniCloud.httpclient.request(WeixinServer.AccessToken_H5_Url, {
+ dataType: 'json',
+ method: 'GET',
+ data: {
+ appid: this._appid,
+ secret: this._secret,
+ grant_type: "client_credential"
+ }
+ })
+ }
+
+ getH5Ticket(access_token) {
+ return uniCloud.httpclient.request(WeixinServer.Ticket_Url, {
+ dataType: 'json',
+ dataAsQueryString: true,
+ method: 'POST',
+ data: {
+ access_token
+ }
+ })
+ }
+
+ getH5AccessTokenForEip() {
+ return uniCloud.httpProxyForEip.postForm(WeixinServer.AccessToken_H5_Url, {
+ appid: this._appid,
+ secret: this._secret,
+ grant_type: "client_credential"
+ }, {
+ dataType: 'json'
+ })
+ }
+
+ getH5TicketForEip(access_token) {
+ return uniCloud.httpProxyForEip.postForm(WeixinServer.Ticket_Url, {
+ access_token
+ }, {
+ dataType: 'json',
+ dataAsQueryString: true
+ })
+ }
+}
+
+WeixinServer.AccessToken_Url = 'https://api.weixin.qq.com/cgi-bin/token'
+WeixinServer.Code2Session_Url = 'https://api.weixin.qq.com/sns/jscode2session'
+WeixinServer.User_Encrypt_Key_Url = 'https://api.weixin.qq.com/wxa/business/getuserencryptkey'
+WeixinServer.AccessToken_H5_Url = 'https://api.weixin.qq.com/cgi-bin/token'
+WeixinServer.Ticket_Url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi'
+
+WeixinServer.GetMPAccessToken = function(options) {
+ return new WeixinServer(options).getAccessToken()
+}
+
+WeixinServer.GetCodeToSession = function(options) {
+ return new WeixinServer(options).codeToSession(options.code)
+}
+
+WeixinServer.GetUserEncryptKey = function(options) {
+ return new WeixinServer(options).getUserEncryptKey(options)
+}
+
+WeixinServer.GetH5AccessToken = function(options) {
+ return new WeixinServer(options).getH5AccessToken()
+}
+
+WeixinServer.GetH5Ticket = function(options) {
+ return new WeixinServer(options).getH5Ticket(options.access_token)
+}
+
+////////////////////////////////////////////////////////////////
+
+function isAliyun() {
+ return (uniCloud.getCloudInfos()[0].provider === 'aliyun')
+}
+
+WeixinServer.GetResponseData = function(response) {
+ console.log("WeixinServer::response", response)
+
+ if (!(response.status === HTTP_STATUS.SUCCESS || response.statusCodeValue === HTTP_STATUS.SUCCESS)) {
+ throw new BridgeError(response.status || response.statusCodeValue, response.status || response.statusCodeValue)
+ }
+
+ const responseData = response.data || response.body
+
+ if (responseData.errcode !== undefined && responseData.errcode !== 0) {
+ throw new BridgeError(responseData.errcode, responseData.errmsg)
+ }
+
+ return responseData
+}
+
+WeixinServer.GetMPAccessTokenData = async function(options) {
+ const response = await new WeixinServer(options).getAccessToken()
+ return WeixinServer.GetResponseData(response)
+}
+
+WeixinServer.GetCodeToSessionData = async function(options) {
+ const response = await new WeixinServer(options).codeToSession(options.code)
+ return WeixinServer.GetResponseData(response)
+}
+
+WeixinServer.GetUserEncryptKeyData = async function(options) {
+ const response = await new WeixinServer(options).getUserEncryptKey(options)
+ return WeixinServer.GetResponseData(response)
+}
+
+WeixinServer.GetH5AccessTokenData = async function(options) {
+ const ws = new WeixinServer(options)
+ let response
+ if (isAliyun()) {
+ response = await ws.getH5AccessTokenForEip()
+ if (typeof response === 'string') {
+ response = JSON.parse(response)
+ }
+ } else {
+ response = await ws.getH5AccessToken()
+ }
+ return WeixinServer.GetResponseData(response)
+}
+
+WeixinServer.GetH5TicketData = async function(options) {
+ const ws = new WeixinServer(options)
+ let response
+ if (isAliyun()) {
+ response = await ws.getH5TicketForEip(options.access_token)
+ if (typeof response === 'string') {
+ response = JSON.parse(response)
+ }
+ } else {
+ response = await ws.getH5Ticket(options.access_token)
+ }
+ return WeixinServer.GetResponseData(response)
+}
+
+
+module.exports = {
+ WeixinServer
+}
diff --git a/uni_modules/uni-open-bridge-common/uniCloud/database/opendb-open-data.schema.json b/uni_modules/uni-open-bridge-common/uniCloud/database/opendb-open-data.schema.json
new file mode 100644
index 0000000000000000000000000000000000000000..9fc8bf91dbcaab05633f09b3706eb7a1e21bc931
--- /dev/null
+++ b/uni_modules/uni-open-bridge-common/uniCloud/database/opendb-open-data.schema.json
@@ -0,0 +1,19 @@
+// 文档教程: https://uniapp.dcloud.net.cn/uniCloud/schema
+{
+ "bsonType": "object",
+ "required": ["_id", "value"],
+ "properties": {
+ "_id": {
+ "bsonType": "string",
+ "description": "key,格式:uni-id:[dcloudAppid]:[platform]:[openid]:[access-token|user-access-token|session-key|encrypt-key-version|ticket]"
+ },
+ "value": {
+ "bsonType": "object",
+ "description": "字段_id对应的值"
+ },
+ "expired": {
+ "bsonType": "date",
+ "description": "过期时间"
+ }
+ }
+}