You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dongfeng-pay/boss/controllers/sendNotifyMerchant.go

76 lines
2.2 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/***************************************************
** @Desc : This file for ...
** @Time : 2019/12/8 22:15
** @Author : yuebin
** @File : send_notify_merchant
** @Last Modified by : yuebin
** @Last Modified time: 2019/12/8 22:15
** @Software: GoLand
****************************************************/
package controllers
import (
"boss/common"
"boss/models"
"fmt"
"github.com/beego/beego/v2/client/httplib"
"github.com/beego/beego/v2/core/logs"
beego "github.com/beego/beego/v2/server/web"
"strings"
)
type SendNotify struct {
beego.Controller
}
func (c *SendNotify) SendNotifyToMerchant() {
bankOrderId := strings.TrimSpace(c.GetString("bankOrderId"))
keyDataJSON := new(KeyDataJSON)
keyDataJSON.Code = -1
orderInfo := models.GetOrderByBankOrderId(bankOrderId)
if orderInfo.Status == common.WAIT {
keyDataJSON.Msg = "该订单不是成功状态,不能回调"
} else {
notifyInfo := models.GetNotifyInfoByBankOrderId(bankOrderId)
notifyUrl := notifyInfo.Url
logs.Info(fmt.Sprintf("boss管理后台手动触发订单回调url=%s", notifyUrl))
req := httplib.Post(notifyUrl)
response, err := req.String()
if err != nil {
logs.Error("回调发送失败fail", err)
keyDataJSON.Msg = fmt.Sprintf("该订单回调发送失败订单回调fail%s", err)
} else {
if !strings.Contains(strings.ToLower(response), "success") {
keyDataJSON.Msg = fmt.Sprintf("该订单回调发送成功但是未返回success字段 商户返回内容=%s", response)
} else {
keyDataJSON.Code = 200
keyDataJSON.Msg = fmt.Sprintf("该订单回调发送成功")
}
}
}
c.Data["json"] = keyDataJSON
c.ServeJSON()
}
func (c *SendNotify) SelfSendNotify() {
bankOrderId := strings.TrimSpace(c.GetString("bankOrderId"))
notifyInfo := models.GetNotifyInfoByBankOrderId(bankOrderId)
keyDataJSON := new(KeyDataJSON)
keyDataJSON.Code = 200
req := httplib.Post(notifyInfo.Url)
response, err := req.String()
if err != nil {
keyDataJSON.Msg = fmt.Sprintf("订单 bankOrderId=%s已经发送回调出错%s", bankOrderId, err)
} else {
keyDataJSON.Msg = fmt.Sprintf("订单 bankOrderId=%s已经发送回调商户返回内容%s", bankOrderId, response)
}
c.Data["json"] = keyDataJSON
c.ServeJSON()
}