import md5 from"../utils/md5";import wxRequest from"../utils/request";import store from"../../store/index";function resortParam(t){const e=Object.keys(t).filter((t=>"sign"!==t)).sort();let r="";return e.forEach((e=>{r+=`${e}${t[e]}`})),r}function getSign(t,e){const r={...t},s=resortParam(t);return r.sign=md5(`plyMinApp${s}plyMinApp`).toUpperCase(),wxRequest(e,{qs:r})}function getSecretSign(t,e){const r=resortParam(t);return md5(`${e}${r}${e}`).toUpperCase()}export const request=async(t,e,r)=>{if(!r){const{apiId:t,apiSecret:r,verifyUrl:s}=store.get("app");for(const n in e)if(("qs"===n||"body"===n)&&e[n]){const o={...e[n]};if(o.appId=t,o.timestamp=Date.now(),s){const t=await getSign(o,s);o.sign=t.data.data.sign}else o.sign=getSecretSign(o,r);e[n]=o}}return wxRequest(t,e)};