Parcourir la source

update

master
dengbiao il y a 4 mois
Parent
révision
3c90c8deb0
4 fichiers modifiés avec 137 ajouts et 47 suppressions
  1. +48
    -46
      app/hdl/hdl_wx_open.go
  2. +2
    -1
      app/router/router.go
  3. +87
    -0
      static/html/success.html
  4. BIN
     

+ 48
- 46
app/hdl/hdl_wx_open.go Voir le fichier

@@ -184,52 +184,54 @@ func GetPreAuthCode(c *gin.Context) {
}

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")
//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.HTML(http.StatusOK, "success.html", gin.H{
"applet_name": "激活鸟",
})
return
}



+ 2
- 1
app/router/router.go Voir le fichier

@@ -33,7 +33,7 @@ func Init() *gin.Engine {
}
r.Use(gin.Recovery())
// r.Use(mw.Limiter)
//r.LoadHTMLGlob("static/html/*")
r.Delims("<<<", ">>>").LoadHTMLGlob("static/html/*")

r.GET("/favicon.ico", func(c *gin.Context) {
c.Status(204)
@@ -50,6 +50,7 @@ func Init() *gin.Engine {
}

func route(r *gin.RouterGroup) {
r.Static("/static", "./static")
r.GET("/test", hdl.Demo)
wxOpenNotify := r.Group("/wxOpen")
{


+ 87
- 0
static/html/success.html Voir le fichier

@@ -0,0 +1,87 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>授权成功</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f2f5;
margin: 0;
}

.container {
text-align: center;
background-color: #fff;
padding: 40px;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
width: 300px;
}

h1 {
color: #333;
margin-bottom: 20px;
}

p {
color: #666;
font-size: 16px;
line-height: 1.5;
}

.btn {
display: inline-block;
padding: 10px 20px;
margin-top: 20px;
font-size: 16px;
color: #fff;
background-color: #5cb85c;
border: none;
border-radius: 4px;
cursor: pointer;
text-decoration: none;
transition: background-color 0.3s;
}

.btn:hover {
background-color: #4cae4c;
}

/* 添加logo样式 */

.logo {

display: block;

margin: 0 auto 20px; /* 上下自动居中,底部外边距20px */

width: 100px; /* 根据你的logo大小调整 */

height: auto; /* 保持图片原始宽高比 */

}
</style>
</head>
<body>
<div class="container">
<!-- 添加logo图片 -->
<img src="../static/img/success.jpeg" alt="Logo" class="logo">
<h1>授权成功!</h1>
<p>您已成功完成微信小程序授权。</p>
<a href="https://open.weixin.qq.com/" class="btn">前往微信</a>
<!-- <button onclick="closeWindow()" class="btn">关闭页面</button>-->
</div>

<script>
function closeWindow() {
window.close();
}
</script>
</body>
</html>


Chargement…
Annuler
Enregistrer