|
|
@ -53,9 +53,14 @@ func Pay(c *gin.Context) (utils.Data, error) {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.NewBusinessError("请求支付宝失败:" + err.Error())
|
|
|
|
return nil, errors.NewBusinessError("请求支付宝失败:" + err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fmt.Println(result.String())
|
|
|
|
fmt.Println(result.String())
|
|
|
|
|
|
|
|
order.PayUrl = result.String()
|
|
|
|
|
|
|
|
order.Token = utils.Md5(order.OrderNo + strconv.Itoa(order.UserId) + strconv.FormatInt(time.Now().Unix(), 10))
|
|
|
|
|
|
|
|
global.DB.Save(order)
|
|
|
|
|
|
|
|
|
|
|
|
data := utils.Data{
|
|
|
|
data := utils.Data{
|
|
|
|
"pay_url": result.String(),
|
|
|
|
"pay_url": global.Config.Server.Domain + "/payment/" + order.Token
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return data, nil
|
|
|
|
return data, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -136,6 +141,16 @@ func Notify(c *gin.Context) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestPost(c *gin.Context) (utils.Data, error) {
|
|
|
|
|
|
|
|
notifyData := make(map[string]interface{})
|
|
|
|
|
|
|
|
notifyData["trade_no"] = "112233"
|
|
|
|
|
|
|
|
notifyData["out_trade_no"] = "2222222"
|
|
|
|
|
|
|
|
notifyData["trade_status"] = "1"
|
|
|
|
|
|
|
|
notifyData["total_amount"] = "11.11"
|
|
|
|
|
|
|
|
notifyResult := postToSdk("https://api.jianghuifa.cn/callback.php/Notify/kd_callback", notifyData)
|
|
|
|
|
|
|
|
return utils.Data{"hello": notifyResult}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func postToSdk(url string, data map[string]interface{}) string {
|
|
|
|
func postToSdk(url string, data map[string]interface{}) string {
|
|
|
|
content, err := json.Marshal(data)
|
|
|
|
content, err := json.Marshal(data)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -187,3 +202,22 @@ func Return(c *gin.Context) {
|
|
|
|
|
|
|
|
|
|
|
|
c.Redirect(http.StatusFound, order.ReturnUrl)
|
|
|
|
c.Redirect(http.StatusFound, order.ReturnUrl)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func Payment(c *gin.Context) {
|
|
|
|
|
|
|
|
var req request.PaymentRequest
|
|
|
|
|
|
|
|
// 将路由参数绑定到结构体中
|
|
|
|
|
|
|
|
if err := c.ShouldBindUri(&req); err != nil {
|
|
|
|
|
|
|
|
c.Writer.WriteHeader(http.StatusOK)
|
|
|
|
|
|
|
|
c.Writer.Write([]byte("参数错误"))
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
order := model.Order{}
|
|
|
|
|
|
|
|
tx := global.DB.Where("token = ?", req.Token).First(&order)
|
|
|
|
|
|
|
|
if tx.Error != nil {
|
|
|
|
|
|
|
|
c.Writer.WriteHeader(http.StatusOK)
|
|
|
|
|
|
|
|
c.Writer.Write([]byte("订单不存在"))
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
c.Redirect(http.StatusFound, order.PayUrl)
|
|
|
|
|
|
|
|
}
|
|
|
|