animeic 1 year ago
parent
commit
e9fdebf0d6
3 changed files with 35 additions and 5 deletions
  1. 2 0
      boxcost/api/plan.go
  2. 31 4
      boxcost/api/sms.go
  3. 2 1
      boxcost/api/supplier.go

+ 2 - 0
boxcost/api/plan.go

@@ -120,6 +120,8 @@ func PlanAllocBatch(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 			if err == nil {
 				wg.Add(1)
 				go SendSmsNotify(smsInfo.Phone, &SupplierSmsReq{smsInfo.Product, smsInfo.SerialNumber}, &wg)
+				// err = SendSmsNotify1(smsInfo.Phone, &SupplierSmsReq{smsInfo.Product, smsInfo.SerialNumber})
+				// fmt.Println(err)
 			}
 		}
 	}

+ 31 - 4
boxcost/api/sms.go

@@ -3,7 +3,6 @@ package api
 import (
 	"box-cost/log"
 	"encoding/json"
-	"errors"
 	"fmt"
 	"sync"
 
@@ -26,14 +25,42 @@ func createSmsClient() (_result *dysmsapi20170525.Client, _err error) {
 }
 
 type SupplierSmsReq struct {
-	Porduct      string
-	SerialNumber string
+	Product      string `json:"product"`
+	SerialNumber string `json:"serialNumber"`
 }
 
 func SendSmsNotify(phone string, info *SupplierSmsReq, wg *sync.WaitGroup) error {
 	defer wg.Done()
 	// TODO dev
-	return errors.New("待配置短信模板")
+	// return errors.New("待配置短信模板")
+	phone = "13408547823"
+	client, _err := createSmsClient()
+	if _err != nil {
+		log.Error(_err)
+		return _err
+	}
+
+	infobytes, _ := json.Marshal(info)
+
+	sendSmsRequest := &dysmsapi20170525.SendSmsRequest{
+		PhoneNumbers:  tea.String(phone),
+		SignName:      tea.String("中鱼互动"),
+		TemplateCode:  tea.String("SMS_460545008"),
+		TemplateParam: tea.String(string(infobytes)),
+	}
+
+	resp, err := client.SendSms(sendSmsRequest)
+	if err != nil {
+		log.Error(err)
+		return err
+	}
+	if *resp.Body.Code == "OK" {
+		return nil
+	}
+
+	return fmt.Errorf("code err %s", *resp.Body.Code)
+}
+func SendSmsNotify1(phone string, info *SupplierSmsReq) error {
 	client, _err := createSmsClient()
 	if _err != nil {
 		log.Error(_err)

+ 2 - 1
boxcost/api/supplier.go

@@ -128,7 +128,7 @@ func genSupplierSmsTemp(billId primitive.ObjectID, billType string, apictx *ApiS
 		return nil, errors.New("手机号信息错误")
 	}
 	return &SupplierSmsTempInfo{
-		Product:      productName,
+		Product:      fmt.Sprintf("%s。【%s】", productName, "成都永红印刷"),
 		SerialNumber: serialNumber,
 		Phone:        user.Phone,
 	}, nil
@@ -177,6 +177,7 @@ func SupplierBillAlloc(c *gin.Context, apictx *ApiSession) (interface{}, error)
 			var wg sync.WaitGroup
 			wg.Add(1)
 			go SendSmsNotify(smsInfo.Phone, &SupplierSmsReq{smsInfo.Product, smsInfo.SerialNumber}, &wg)
+			// err = SendSmsNotify1(smsInfo.Phone, &SupplierSmsReq{smsInfo.Product, smsInfo.SerialNumber})
 			wg.Wait()
 		}
 	}