|
|
@@ -1,6 +1,7 @@ |
|
|
|
package hdl |
|
|
|
|
|
|
|
import ( |
|
|
|
"applet/app/cfg" |
|
|
|
"applet/app/e" |
|
|
|
"applet/app/lib/wechat" |
|
|
|
"applet/app/md" |
|
|
@@ -149,7 +150,10 @@ func GetPreAuthCode(c *gin.Context) { |
|
|
|
} |
|
|
|
|
|
|
|
c.Writer.Header().Set("Access-Control-Allow-Origin", "*") |
|
|
|
redirectURI := "http://super.admin.izhyin.com/Wx/getAuthUrlCallBack" |
|
|
|
redirectURI := "http://super.advertisement.dengbiao.top/api/wxOpen/getAuthUrlCallBack?masterId=" + masterId |
|
|
|
if cfg.Prd { |
|
|
|
redirectURI = "http://www.baidu.com/api/wxOpen/getAuthUrlCallBack?masterId=" + masterId |
|
|
|
} |
|
|
|
// 对redirectURI进行URL编码 |
|
|
|
encodedRedirectURI := url.QueryEscape(redirectURI) |
|
|
|
|
|
|
@@ -179,6 +183,56 @@ func GetPreAuthCode(c *gin.Context) { |
|
|
|
</script>`, authURL) |
|
|
|
} |
|
|
|
|
|
|
|
func GetAuthUrlCallBack(c *gin.Context) { |
|
|
|
authCode := c.DefaultQuery("auth_code", "") |
|
|
|
if authCode == "" { |
|
|
|
e.OutErr(c, e.ERR_NOT_FAN, "auth_code获取失败") |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
fmt.Println("auth_code>>>>>>>>", authCode) |
|
|
|
|
|
|
|
masterId := c.DefaultQuery("masterId", "") |
|
|
|
wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db) |
|
|
|
wxOpenThirdPartyAppList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId)) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
if wxOpenThirdPartyAppList == nil { |
|
|
|
e.OutErr(c, e.ERR_NOT_FAN, "未查询到对应三方应用记录") |
|
|
|
return |
|
|
|
} |
|
|
|
wxApiService, err := wechat.NewWxApiService(masterId, wxOpenThirdPartyAppList.Appid, wxOpenThirdPartyAppList.AppSecret) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
resp, err := wxApiService.GetAuthorizerAccessTokenByAuthCode(authCode) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
userWxAppletListDb := implement.NewUserWxAppletListDb(db.Db) |
|
|
|
userWxAppletList, err := userWxAppletListDb.GetUserWxAppletListByAppId(resp.AuthorizationInfo.AuthorizerAppid) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
if userWxAppletList == nil { |
|
|
|
e.OutErr(c, e.ERR_NOT_FAN, "未查询到小程序应用记录") |
|
|
|
return |
|
|
|
} |
|
|
|
userWxAppletList.AuthorizerRefreshToken = resp.AuthorizationInfo.AuthorizerRefreshToken |
|
|
|
_, err = userWxAppletListDb.UpdateUserWxAppletList(userWxAppletList, "authorizer_refresh_token") |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
c.String(http.StatusOK, "ok") |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func WechatMsgRecieve(c *gin.Context) { |
|
|
|
|
|
|
|
return |
|
|
|