package services import ( "PaymentCenter/app/constants/common" "PaymentCenter/app/http/entities/front" "PaymentCenter/app/models/paychannelmodel" "PaymentCenter/app/third/paymentService" "PaymentCenter/config" "encoding/json" "net/url" "strconv" ) // 获取授权链接 func GetWxAuthUrl(param front.GetWxAuthUrlRequest) (targetUrl string, code int) { var ( // 重定向地址 redirectUri = config.GetConf().PayService.Host + common.FRONT_V1 + "/wx/getOpenId" ) baseUrl := "https://open.weixin.qq.com/connect/oauth2/authorize" // 获取支付渠道的配置 id, err := strconv.Atoi(param.PayChannelId) if err != nil { code = handErr(err) return } payChannel := paychannelmodel.PayChannel{Id: int64(id)} code = PayChannelGet(&payChannel) if code != 200 { return } //// 配置解析 //wxConfig := paymentService.WxPay{} //err = json.Unmarshal([]byte(payChannel.ExtJson), &wxConfig) //if err != nil { // code = handErr(err) // return //} appid := payChannel.AppId redirectUri = url.QueryEscape(redirectUri) responseType := "code" scope := "snsapi_base" targetUrl = baseUrl + "?appid=" + appid + "&redirect_uri=" + redirectUri + "&response_type=" + responseType + "&scope=" + scope + "#wechat_redirect" return } // 通过code换取网页授权access_token func GetWxAuth(param front.GetWxAuthRequest) (code int) { // 获取支付渠道的配置 id, err := strconv.Atoi(param.PayChannelId) if err != nil { code = handErr(err) return } payChannel := paychannelmodel.PayChannel{Id: int64(id)} code = PayChannelGet(&payChannel) if code != 200 { return } // 配置解析 wxConfig := paymentService.WxPay{} err = json.Unmarshal([]byte(payChannel.ExtJson), &wxConfig) if err != nil { code = handErr(err) return } //targetUrl := fmt.Sprintf("https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code", // payChannel.AppId, // wxConfig.SerialNo, // param.Code, //) return }