"use strict";const e=require("../common/vendor.js"),r=require("../config/user.js"),o=require("../config/url.js");exports.getQueryString=function(e,r){var o=new RegExp("(^|&|/?)"+r+"=([^&|/?]*)(&|/?|$)","i"),n=e.substr(1).match(o);return null!=n?n[2]:null},exports.getUserInfo=()=>new Promise((async(e,o)=>{e(await r.getMyIndexInfo({isHide:!1}))})),exports.getUserPhoneNumber=r=>new Promise((async(n,t)=>{try{const s=e.index.getStorageSync("token");if(!s)return void t(new Error("用户未登录"));console.log("开始请求获取手机号，code=",r,"请求地址=",o.URL+"/app/user/getPhoneNumber"),e.index.request({url:o.URL+"/app/user/getPhoneNumber",method:"POST",header:{Authorization:"Bearer "+s,clientId:e.index.getStorageSync("client_id"),"Content-Type":"application/json"},data:{code:r,appid:o.appid},success:e=>{console.log("请求获取手机号接口成功，原始响应:",JSON.stringify(e)),200===e.statusCode?e.data?n(e.data):t(new Error("服务器返回空数据")):t(new Error(`HTTP错误: ${e.statusCode}`))},fail:e=>{console.error("请求获取手机号接口网络错误:",e),t(new Error("请求获取手机号接口失败: "+(e.errMsg||JSON.stringify(e))))}})}catch(s){console.error("获取手机号过程中出现异常:",s),t(new Error("获取手机号异常: "+(s.message||JSON.stringify(s))))}})),exports.initiateWeChatScorePayment=r=>new Promise(((o,n)=>{r&&r.data&&r.data.package?e.wx$1.openBusinessView({businessType:"wxpayScoreUse",extraData:{mch_id:r.data.mch_id,package:r.data.package},success:e=>{"openBusinessView:ok"===e.errMsg?o(e):n(new Error("支付流程未完成"))},fail:r=>{console.error("微信支付分小程序调用失败",r),e.index.showToast({title:r.errMsg||"支付分接口调用失败",icon:"none"}),n(r)}}):n(new Error("支付参数不完整"))})),exports.wxLogin=()=>new Promise(((o,n)=>{e.index.login({provider:"weixin",success:async t=>{try{if(!t.code)throw new Error("获取微信登录凭证失败");{const n=await r.login({code:t.code,appid:"wx2165f0be356ae7a9"});if(200!==n.code)throw new Error(n.message||"登录失败");e.index.setStorageSync("token",n.data.LoginWxVo.access_token),e.index.setStorageSync("client_id",n.data.LoginWxVo.client_id),o(n.data)}}catch(s){e.index.showToast({title:s.message||"登录失败",icon:"none"}),n(s)}},fail:r=>{e.index.showToast({title:"微信登录失败",icon:"none"}),n(r)}})}));
