|
|
@@ -10,18 +10,21 @@ import (
|
|
|
model2 "cold-delivery/common/model"
|
|
|
"cold-delivery/common/nats/nats_server"
|
|
|
"cold-delivery/conf"
|
|
|
+ "encoding/json"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
- "go.uber.org/zap"
|
|
|
- "gogs.baozhida.cn/zoie/OAuth-core/pkg/sms"
|
|
|
- "gogs.baozhida.cn/zoie/OAuth-core/pkg/utils"
|
|
|
- "gogs.baozhida.cn/zoie/OAuth-core/service"
|
|
|
- "gorm.io/gorm"
|
|
|
+ http "net/http"
|
|
|
"net/url"
|
|
|
"sort"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
+
|
|
|
+ "go.uber.org/zap"
|
|
|
+ "gogs.baozhida.cn/zoie/OAuth-core/pkg/sms"
|
|
|
+ "gogs.baozhida.cn/zoie/OAuth-core/pkg/utils"
|
|
|
+ "gogs.baozhida.cn/zoie/OAuth-core/service"
|
|
|
+ "gorm.io/gorm"
|
|
|
)
|
|
|
|
|
|
type Waybill struct {
|
|
|
@@ -781,10 +784,10 @@ func (e *Waybill) Delivery(c *dto.WaybillDeliveryReq, p *actions.DataPermission)
|
|
|
return errors.New("保存保温箱记录失败")
|
|
|
}
|
|
|
}
|
|
|
- // 配送中状态下才发送短信
|
|
|
- ss := sms.NewSMS(conf.ExtConfig.SubMail.Appid, conf.ExtConfig.SubMail.Signature)
|
|
|
+ // 配送中状态下才发送短信 (改用普通短信 Send,无需模板)
|
|
|
+ // 配送中状态下才发送短信(改用自定义模板发送)
|
|
|
addr := conf.ExtConfig.Applet.WaybillUrl + url.QueryEscape(lib.AesEncryptCBC(waybillModel.WaybillNo, lib.AesKey))
|
|
|
- res, err1 := ss.SmsXSend(waybillModel.ConsigneeAddressPhone, addr)
|
|
|
+ res, err1 := CustomSmsXSend(conf.ExtConfig.SubMail.Appid, conf.ExtConfig.SubMail.Signature, waybillModel.ConsigneeAddressPhone, addr)
|
|
|
if err1 != nil || res.Status != sms.SUCCESS {
|
|
|
e.Log.Errorf("派单短信发送失败", zap.Any("res", res), zap.Error(err1))
|
|
|
err = errors.New("派单短信发送失败,请检查收件人电话是否正确!")
|
|
|
@@ -792,7 +795,7 @@ func (e *Waybill) Delivery(c *dto.WaybillDeliveryReq, p *actions.DataPermission)
|
|
|
}
|
|
|
waybillModel.SendLog = model.WaybillSendLog{
|
|
|
Phone: waybillModel.ConsigneeAddressPhone,
|
|
|
- Content: "【贵州宝智达冷链科技有限公司】您的运单正在派送中,点击查看详情:" + addr,
|
|
|
+ Content: "【贵州宝智达冷链科技公司】您的订单正在派送中,点击查看详情:" + addr, // 同步改成新模板的文案
|
|
|
}
|
|
|
//// 查询任务
|
|
|
//var logistics model.WaybillLogistics
|
|
|
@@ -1907,10 +1910,9 @@ func (e *Waybill) SecondaryDistribution(c *dto.WaybillAssignment, p *actions.Dat
|
|
|
e.Log.Errorf("更新运单失败: %s", err)
|
|
|
return global.UpdateFailedErr
|
|
|
}
|
|
|
- // 二次分配订单发送短信
|
|
|
- ss := sms.NewSMS(conf.ExtConfig.SubMail.Appid, conf.ExtConfig.SubMail.Signature)
|
|
|
+ // 二次分配订单发送短信(改用自定义模板发送)
|
|
|
addr := conf.ExtConfig.Applet.WaybillUrl + url.QueryEscape(lib.AesEncryptCBC(waybil.WaybillNo, lib.AesKey))
|
|
|
- res, err1 := ss.SmsXSend(c.ConsigneeAddressPhone, addr)
|
|
|
+ res, err1 := CustomSmsXSend(conf.ExtConfig.SubMail.Appid, conf.ExtConfig.SubMail.Signature, c.ConsigneeAddressPhone, addr)
|
|
|
if err1 != nil || res.Status != sms.SUCCESS {
|
|
|
e.Log.Errorf("派单短信发送失败", zap.Any("res", res), zap.Error(err1))
|
|
|
err = errors.New("派单短信发送失败,请检查收件人电话是否正确!")
|
|
|
@@ -1918,7 +1920,7 @@ func (e *Waybill) SecondaryDistribution(c *dto.WaybillAssignment, p *actions.Dat
|
|
|
}
|
|
|
waybil.SendLog = model.WaybillSendLog{
|
|
|
Phone: c.ConsigneeAddressPhone,
|
|
|
- Content: "【贵州宝智达冷链科技有限公司】您的运单正在派送中,点击查看详情:" + addr,
|
|
|
+ Content: "【贵州宝智达冷链科技公司】您的订单正在派送中,点击查看详情:" + addr, // 同步改成新模板的文案
|
|
|
}
|
|
|
// 添加物流
|
|
|
logisticsObj := model.WaybillLogistics{
|
|
|
@@ -1969,3 +1971,35 @@ func (e *Waybill) SecondaryDistribution(c *dto.WaybillAssignment, p *actions.Dat
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
+
|
|
|
+// CustomSmsXSend 自定义模板短信发送,使用新模板 Z5wH13
|
|
|
+func CustomSmsXSend(appid, signature, to, addr string) (sms.XSendRes, error) {
|
|
|
+ vars := map[string]string{"addr": addr}
|
|
|
+ varsBytes, _ := json.Marshal(vars)
|
|
|
+
|
|
|
+ payload := url.Values{}
|
|
|
+ payload.Set("appid", appid)
|
|
|
+ payload.Set("signature", signature)
|
|
|
+ payload.Set("to", to)
|
|
|
+ payload.Set("project", "Z5wH13") // 你的新模板ID
|
|
|
+ payload.Set("vars", string(varsBytes))
|
|
|
+
|
|
|
+ req, err := http.NewRequest("POST", "https://api-v4.mysubmail.com/sms/xsend", strings.NewReader(payload.Encode()))
|
|
|
+ if err != nil {
|
|
|
+ return sms.XSendRes{}, err
|
|
|
+ }
|
|
|
+ req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+
|
|
|
+ client := &http.Client{}
|
|
|
+ resp, err := client.Do(req)
|
|
|
+ if err != nil {
|
|
|
+ return sms.XSendRes{}, err
|
|
|
+ }
|
|
|
+ defer resp.Body.Close()
|
|
|
+
|
|
|
+ var res sms.XSendRes
|
|
|
+ if err := json.NewDecoder(resp.Body).Decode(&res); err != nil {
|
|
|
+ return sms.XSendRes{}, err
|
|
|
+ }
|
|
|
+ return res, nil
|
|
|
+}
|