import{C as d,D as i,N as m,n as g}from"./index-BGEOEKbF.js";const p="https://res.wx.qq.com/open/js/jweixin-1.6.0.js",f=d.getConfig("server_path")+"user/wx/jsapi_sign",w=/micromessenger/i.test(navigator.userAgent),S=/miniProgram/i.test(navigator.userAgent),x=location.origin.length>12&&location.origin.indexOf("192.168")<0&&w,l=window;function _(t,e=1e5){const r=document.createElement("script"),a=document.getElementsByTagName("head")[0];r.type="text/javascript",r.src=t;const n=i();return r.addEventListener("load",function(){n.resolve("")},!1),setTimeout(()=>{n.reject("timeout")},e),a.appendChild(r),n.promise}function j(){return l.wx?i.when(l.wx):_(p).then(()=>l.wx)}let s;function u(){if(!x)return i.reject("not wx");if(s)return i.when(s);const t=s=i();return i.when(l.wx||j()).then(e=>{const r=encodeURIComponent(location.href.split("#")[0]),a=d.getConfig("app_wx");m.post(f,{name:a.name,url:r}).then(n=>{const o=n.data.config;if(!o){t.reject("config error!"),s=void 0;return}e.config({debug:!1,appId:o.appId,timestamp:o.timestamp,nonceStr:o.nonceStr,signature:o.signature,jsApiList:["updateTimelineShareData","updateAppMessageShareData","onMenuShareQQ","onMenuShareWeibo","onMenuShareQZone","startRecord","stopRecord","onVoiceRecordEnd","playVoice","pauseVoice","stopVoice","onVoicePlayEnd","uploadVoice","downloadVoice","chooseImage","previewImage","uploadImage","downloadImage","translateVoice","getNetworkType","openLocation","getLocation","hideOptionMenu","showOptionMenu","hideMenuItems","showMenuItems","hideAllNonBaseMenuItem","showAllNonBaseMenuItem","closeWindow","scanQRCode","chooseWXPay"]}),e.ready(function(){s=e,t.resolve(e)}),e.error(function(h){console.error("JSSDK失败",h),t.reject("JSSDK失败"),s=void 0})}).catch(n=>{t.reject({text:"getWjSign error!",e:n}),s=void 0})}),t.promise}function c(t,e){const r=i(),a={success:n=>r.resolve(n),fail:n=>r.reject(n)};return u().then(n=>{e=g.extend({},a,e),n[t](e)}),r.promise}function v(t){const e=d.getConfig("wx_share");return t=g.extend({},e,t),t.shareTitle=t.shareTitle||t.title,u().then(r=>y(r,t))}function y(t,e){if(S&&t.miniProgram){let n=location.hash;if(e.link){const o=e.link.split("#");n=o[o.length-1],n[0]=="#"&&(n=n.substring(1))}return t.miniProgram.postMessage({data:{type:"微信分享",data:{title:e.shareTitle,desc:e.desc,imageUrl:e.imgUrl,path:n}}})}const r=c("updateAppMessageShareData",{title:e.title,desc:e.desc,link:e.link,imgUrl:e.imgUrl}),a=c("updateTimelineShareData",{title:e.shareTitle,link:e.link,imgUrl:e.imgUrl});return i.all([r,a])}function C(){return c("getLocation",{type:"gcj02"}).then(t=>t.resultStr)}function I(){return c("scanQRCode",{needResult:1,scanType:["qrCode","barCode"]}).then(e=>{const r=e.latitude,a=e.longitude,n=e.speed,o=e.accuracy;return{lat:r,lng:a,speed:n,accuracy:o}})}function M(t,e=0){return c("previewImage",{urls:t,current:t[e]})}const W={initWx:u,setShare:v,get_wx_pos:C,QrCode:I,preview:M};export{W};
