Browse Source

Merge branch 'master' into feature/migrate_wecht_msg

# Conflicts:
#	controllers/admin_wx.go
#	controllers/base_common.go
#	controllers/wechat.go
#	models/tables/admin/admin.go
#	services/admin_wechat.go
#	services/sms.go
#	utils/config.go
xiexiaoyuan 2 năm trước cách đây
mục cha
commit
e9ac1d7344

+ 69 - 1
controllers/wechat.go

@@ -2,6 +2,7 @@ package controllers
 
 
 import (
 import (
 	"encoding/json"
 	"encoding/json"
+	"encoding/xml"
 	"fmt"
 	"fmt"
 	"github.com/medivhzhan/weapp/v2"
 	"github.com/medivhzhan/weapp/v2"
 	adminResp "hongze/hongze_mobile_admin/models/response/admin"
 	adminResp "hongze/hongze_mobile_admin/models/response/admin"
@@ -9,6 +10,7 @@ import (
 	"hongze/hongze_mobile_admin/services"
 	"hongze/hongze_mobile_admin/services"
 	"hongze/hongze_mobile_admin/utils"
 	"hongze/hongze_mobile_admin/utils"
 	"strconv"
 	"strconv"
+	"time"
 )
 )
 
 
 type WeChatCommon struct {
 type WeChatCommon struct {
@@ -301,7 +303,6 @@ func (c *WeChatCommon) AdminWeChatLogin() {
 		c.FailWithMessage(fmt.Sprintf("%v", err), fmt.Sprintf("%v", err))
 		c.FailWithMessage(fmt.Sprintf("%v", err), fmt.Sprintf("%v", err))
 		return
 		return
 	}
 	}
-	
 	if item.Errcode != 0 {
 	if item.Errcode != 0 {
 		if item.Errcode == 40163 {
 		if item.Errcode == 40163 {
 			c.FailWithCodeUsed("获取用户信息失败", "获取access_token 失败 errCode:"+strconv.Itoa(item.Errcode)+" ;errMsg:"+item.Errmsg)
 			c.FailWithCodeUsed("获取用户信息失败", "获取access_token 失败 errCode:"+strconv.Itoa(item.Errcode)+" ;errMsg:"+item.Errmsg)
@@ -376,4 +377,71 @@ func (c *WeChatCommon) AdminWeChatLogin() {
 	}
 	}
 
 
 	c.OkDetailed(resp, "登录成功")
 	c.OkDetailed(resp, "登录成功")
+}
+
+// @Title 微信获取签名接口
+// @Description 微信获取签名接口
+// @Param   Url   query   string  true       "url地址"
+// @Success 200 {object} models.WechatSign
+// @router /notify [get,post]
+func (c *WeChatCommon) Notify() {
+	echostr := c.GetString("echostr")
+	method := c.Ctx.Input.Method()
+	if method == "POST" {
+		body := c.Ctx.Input.RequestBody
+		utils.FileLog.Info("wechat notify:" + string(body))
+		item := new(Notify)
+		err := xml.Unmarshal(body, &item)
+		if err != nil {
+			utils.FileLog.Info("xml.Unmarshal:" + err.Error())
+		}
+		contactMsg := "感谢关注弘则内部。\n\n此公众号仅供内部员工使用,用于内部员工接收消息通知"
+
+		var openId, returnResult string
+		if item.MsgType != "" {
+			openId = item.FromUserName
+		}
+		xmlTpl := `<xml>
+		<ToUserName><![CDATA[%s]]></ToUserName>
+		<FromUserName><![CDATA[%s]]></FromUserName>
+		<CreateTime>%s</CreateTime>
+		<MsgType><![CDATA[text]]></MsgType>
+		<Content><![CDATA[%s]]></Content>
+		</xml>`
+		createTime := strconv.FormatInt(time.Now().Unix(), 10)
+		xmlTpl = fmt.Sprintf(xmlTpl, openId, utils.WxId, createTime, contactMsg)
+
+		if item.MsgType == "event" {
+			switch item.Event {
+			case "subscribe":
+				fmt.Println("关注")
+			//	go models.UserSubscribe(1, openId)
+				break
+			case "unsubscribe":
+				fmt.Println("取消关注")
+			//	go models.UserSubscribe(0, openId)
+				break
+			case "CLICK":
+				returnResult = xmlTpl
+				break
+			default:
+				utils.FileLog.Info("wechat notify event:" + item.Event)
+			}
+			c.Ctx.WriteString(xmlTpl)
+		} else {
+			returnResult = xmlTpl
+		}
+		c.Ctx.WriteString(returnResult)
+	} else {
+		c.Ctx.WriteString(echostr)
+	}
+}
+
+type Notify struct {
+	ToUserName   string `xml:"ToUserName"`
+	FromUserName string `xml:"FromUserName"`
+	CreateTime   int    `xml:"CreateTime"`
+	MsgType      string `xml:"MsgType"`
+	Event        string `xml:"Event"`
+	EventKey     string `xml:"EventKey"`
 }
 }

+ 1 - 1
models/tables/admin/admin.go

@@ -184,4 +184,4 @@ func GetOpenIdListByMobile(mobile, openIdStr string) (items []*OpenIdList, err e
 	}
 	}
 	_, err = orm.NewOrm().Raw(sql, mobile).QueryRows(&items)
 	_, err = orm.NewOrm().Raw(sql, mobile).QueryRows(&items)
 	return
 	return
-}
+}

+ 9 - 0
routers/commentsRouter.go

@@ -691,6 +691,15 @@ func init() {
             Filters: nil,
             Filters: nil,
             Params: nil})
             Params: nil})
 
 
+    beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers:WeChatCommon"] = append(beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers:WeChatCommon"],
+        beego.ControllerComments{
+            Method: "Notify",
+            Router: `/notify`,
+            AllowHTTPMethods: []string{"get","post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers:WeChatCommon"] = append(beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers:WeChatCommon"],
     beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers:WeChatCommon"] = append(beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers:WeChatCommon"],
         beego.ControllerComments{
         beego.ControllerComments{
             Method: "WxAppLogin",
             Method: "WxAppLogin",

+ 1 - 0
utils/config.go

@@ -220,6 +220,7 @@ func wxConfig() {
 		//内部员工公众号(弘则部门)
 		//内部员工公众号(弘则部门)
 		AdminWxAppId = "wx1392111da5426e9e"
 		AdminWxAppId = "wx1392111da5426e9e"
 		AdminWxAppSecret = "30eceb7cf29bf2f046031155ab55d7b4"
 		AdminWxAppSecret = "30eceb7cf29bf2f046031155ab55d7b4"
+
 		SendWxTemplateMsgUrl = "http://127.0.0.1:8086/v1/wechat/send_template_msg"
 		SendWxTemplateMsgUrl = "http://127.0.0.1:8086/v1/wechat/send_template_msg"
 	}
 	}
 
 

+ 6 - 0
utils/constants.go

@@ -143,6 +143,12 @@ const (
 	TEMPLATE_MSG_CYGX_ARTICLE_ADD                 //查研观向报告更新推送  13
 	TEMPLATE_MSG_CYGX_ARTICLE_ADD                 //查研观向报告更新推送  13
 	TEMPLATE_MSG_YB_PRICE_DRIVEN                  //研报价格驱动 14
 	TEMPLATE_MSG_YB_PRICE_DRIVEN                  //研报价格驱动 14
 	TEMPLATE_MSG_SEAL_FINISHED                    //用印申请已迁回通知 15
 	TEMPLATE_MSG_SEAL_FINISHED                    //用印申请已迁回通知 15
+	TEMPLATE_MSG_YB_COMMUNITY_VIDEO               //研报视频社区 16
+	TEMPLATE_MSG_MOVE_SELLER                      //销售"移动/删除联系人"权限变更通知 17
+	TEMPLATE_MSG_YB_VOICE_BROADCAST               //研报语音播报 18
+	TEMPLATE_MSG_YB_VIDEO_UPLOAD                  //研报视频上传 19
+	TEMPLATE_MSG_YB_ROAD_VIDEO                    //研报线上路演 20
+	TEMPLATE_MSG_CYGX_ROADSHOW_VIDEO              //查研观向微路演视频 21
 )
 )