|
|
@ -38,6 +38,10 @@ func PutOrderDelayQueue(body, outTradeNo, openId string, amount, status int, exp |
|
|
|
expires = time.Now().Add(2 * time.Hour).Unix() // 2 个小时
|
|
|
|
} |
|
|
|
|
|
|
|
if delay == 0 { |
|
|
|
delay = 100 |
|
|
|
} |
|
|
|
|
|
|
|
orderDelayQueue <- &orderDelayQueueParam{ |
|
|
|
First: true, |
|
|
|
Expires: expires, |
|
|
@ -83,7 +87,7 @@ func loopUnifiedOrder() { |
|
|
|
|
|
|
|
// 首次进入不延迟
|
|
|
|
if !param.First { |
|
|
|
time.Sleep(time.Duration(param.Delay) * time.Second) |
|
|
|
time.Sleep(time.Duration(param.Delay) * time.Millisecond) |
|
|
|
} |
|
|
|
param.First = false |
|
|
|
|
|
|
@ -192,6 +196,37 @@ func UnifiedOrder(body, openid string, fee, goodType, userId, activityId int64) |
|
|
|
}, nil |
|
|
|
} |
|
|
|
|
|
|
|
func ReOrder(outTradeNo string) (map[string]interface{}, error) { |
|
|
|
userOrder := new(models.UserOrder) |
|
|
|
exist, err := userOrder.GetByOutTradeNo(outTradeNo) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
if !exist { |
|
|
|
return nil, errors.New("订单不存在") |
|
|
|
} |
|
|
|
|
|
|
|
timestamp := strconv.FormatInt(time.Now().Unix(), 10) |
|
|
|
nonceStr := utils.RandomStr(32) |
|
|
|
//获取H5支付需要的paySign
|
|
|
|
pac := "prepay_id=" + userOrder.PrepayId |
|
|
|
paySign := core2.JsapiSign(Appid, timestamp, nonceStr, pac, core2.SignType_MD5, ApiKey) |
|
|
|
if userOrder.TimeExpire <= core2.FormatTime(time.Now()) { |
|
|
|
go PutOrderDelayQueue(userOrder.Body, userOrder.OutTradeNo, userOrder.OpenId, int(userOrder.TotalFee), userOrder.Status, 0, 0) |
|
|
|
} |
|
|
|
return map[string]interface{}{ |
|
|
|
"appid": Appid, |
|
|
|
"timestamp": timestamp, |
|
|
|
"nonce_str": nonceStr, |
|
|
|
"package": pac, |
|
|
|
"sign_type": core2.SignType_MD5, |
|
|
|
"pay_sign": paySign, |
|
|
|
"out_trade_no": outTradeNo, |
|
|
|
"user_order_id": userOrder.Id, |
|
|
|
}, nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Notify
|
|
|
|
type NotifyRequest struct { |
|
|
|
ReturnCode string `xml:"return_code,omitempty" json:"return_code,omitempty"` |
|
|
|