ソースを参照

提交代码修改

DESKTOP-HN5QP3V\Administrator 2 ヶ月 前
コミット
e2d6b69638
2 ファイル変更8 行追加2 行削除
  1. 5 2
      app/service/subscribe.go
  2. 3 0
      pkg/helper/wechat/wechatHelper.go

+ 5 - 2
app/service/subscribe.go

@@ -35,7 +35,7 @@ func (s *SubscribeOpenService) createSubscribe(deviceId, openId, module string)
 	return mgm.Coll(sub).Create(sub)
 }
 
-func (this *SubscribeOpenService) updateSubscribe(deviceId string, module string) error {
+func (this *SubscribeOpenService) updateSubscribe(deviceId string, openId string, module string) error {
 	now := util.GetNowSecond()
 
 	filter := bson.M{"device_id": deviceId}
@@ -43,6 +43,7 @@ func (this *SubscribeOpenService) updateSubscribe(deviceId string, module string
 	update := bson.M{
 		"$set": bson.M{
 			"device_id": deviceId,
+			"open_id":   openId,
 			"modules." + module: bson.M{
 				"enabled": true,
 				"open_at": now,
@@ -60,6 +61,8 @@ func (this *SubscribeOpenService) updateSubscribe(deviceId string, module string
 }
 
 func (this *SubscribeOpenService) Open() error {
+	logger.Info("user sign subscribe device_id: %s  open_id: %s, module: %s", this.DeviceId, this.OpenId, this.Module)
+
 	subscribeOne := new(subscribe.Subscribe)
 	err := mgm.Coll(&subscribe.Subscribe{}).First(bson.M{"device_id": this.DeviceId}, subscribeOne)
 	if err != nil {
@@ -72,7 +75,7 @@ func (this *SubscribeOpenService) Open() error {
 		// 2️⃣ 其他错误
 		return err
 	}
-	return this.updateSubscribe(this.DeviceId, this.Module)
+	return this.updateSubscribe(this.DeviceId, this.OpenId, this.Module)
 }
 
 type SubscribeCloseService struct {

+ 3 - 0
pkg/helper/wechat/wechatHelper.go

@@ -68,6 +68,7 @@ type Subscribe struct {
 func (this *WechatHelper) SendWechatSubscribe(openid string, template string, msg interface{}) int {
 	token, _ := this.Wechat.GetAccessToken()
 	url := subscribeUrl + token
+	logger.Info("send msg use template %s, url %s", template, url)
 	reqData := Subscribe{ToUser: openid, TemplateId: template, Lang: "zh_CN"}
 	reqData.Data = msg
 
@@ -95,5 +96,7 @@ func (this *WechatHelper) SendWechatSubscribe(openid string, template string, ms
 			return re.Result.Label
 		}
 	}
+
+	logger.Info("==============> %v", re)
 	return re.Errcode
 }