|
@@ -1,14 +1,18 @@
|
|
|
package user
|
|
|
|
|
|
import (
|
|
|
+ "encoding/xml"
|
|
|
"eta/eta_mini_ht_api/common/component/cache"
|
|
|
logger "eta/eta_mini_ht_api/common/component/log"
|
|
|
"eta/eta_mini_ht_api/common/exception"
|
|
|
authUtils "eta/eta_mini_ht_api/common/utils/auth"
|
|
|
"eta/eta_mini_ht_api/controllers"
|
|
|
+ "eta/eta_mini_ht_api/service/auth"
|
|
|
"eta/eta_mini_ht_api/service/user"
|
|
|
"fmt"
|
|
|
+ "strconv"
|
|
|
"strings"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
|
|
@@ -405,3 +409,100 @@ func covertToUserProfile(user user.User) UserProfileReq {
|
|
|
Mobile: user.Mobile,
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (u *UserController) BindGzh() {
|
|
|
+ controllers.Wrap(&u.BaseController, func() (result *controllers.WrapData, err error) {
|
|
|
+ result = u.InitWrapData("获取我的未读消息失败")
|
|
|
+ bindReq := new(BindGzhReq)
|
|
|
+ u.GetPostParams(bindReq)
|
|
|
+ code := bindReq.Code
|
|
|
+ isBind, err := auth.BindWxGzh(code)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("绑定公众号失败:%v", err)
|
|
|
+ u.FailedResult("绑定公众号失败", result)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ u.SuccessResult("绑定成功", IsBindGzhRes{
|
|
|
+ IsBind: isBind,
|
|
|
+ }, result)
|
|
|
+ return
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+type IsBindGzhRes struct {
|
|
|
+ IsBind bool `json:"isBind"`
|
|
|
+}
|
|
|
+
|
|
|
+type BindGzhReq struct {
|
|
|
+ Code string `json:"Code"`
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (u *UserController) Notify() {
|
|
|
+ echostr := u.GetString("echostr")
|
|
|
+ method := u.Ctx.Input.Method()
|
|
|
+ if method == "POST" {
|
|
|
+ body := u.Ctx.Input.RequestBody
|
|
|
+ item := new(Notify)
|
|
|
+ err := xml.Unmarshal(body, &item)
|
|
|
+ if err != nil {
|
|
|
+ logger.Info("xml.Unmarshal:" + err.Error())
|
|
|
+ }
|
|
|
+ contactMsg := ""
|
|
|
+
|
|
|
+ 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, "gh_b2f5b115ec8d", createTime, contactMsg)
|
|
|
+
|
|
|
+ if item.MsgType == "event" {
|
|
|
+ switch item.Event {
|
|
|
+ case "subscribe":
|
|
|
+ fmt.Println("关注")
|
|
|
+
|
|
|
+ case "unsubscribe":
|
|
|
+ fmt.Println("取消关注")
|
|
|
+
|
|
|
+ case "CLICK":
|
|
|
+ returnResult = xmlTpl
|
|
|
+ default:
|
|
|
+ logger.Info("wechat notify event:" + item.Event)
|
|
|
+ }
|
|
|
+ u.Ctx.WriteString(xmlTpl)
|
|
|
+ } else {
|
|
|
+ returnResult = xmlTpl
|
|
|
+ }
|
|
|
+ u.Ctx.WriteString(returnResult)
|
|
|
+ } else {
|
|
|
+ u.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"`
|
|
|
+ Content string `xml:"Content"`
|
|
|
+}
|