fadd
This commit is contained in:
@@ -206,8 +206,35 @@ func (w *WechatPayService) CreateWechatMiniProgramOrder(ctx context.Context, amo
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("微信支付订单创建失败: %v, 状态码: %d", err, result.Response.StatusCode)
|
||||
}
|
||||
// 返回预支付交易会话标识
|
||||
return resp, nil
|
||||
// 显式转为 map,确保小程序 uni.requestPayment 能正确解析(避免指针序列化问题)
|
||||
return jsapiRespToMap(resp), nil
|
||||
}
|
||||
|
||||
// jsapiRespToMap 将 PrepayWithRequestPaymentResponse 转为 map,供小程序/JSAPI 调起支付
|
||||
func jsapiRespToMap(resp *jsapi.PrepayWithRequestPaymentResponse) map[string]string {
|
||||
m := make(map[string]string)
|
||||
if resp == nil {
|
||||
return m
|
||||
}
|
||||
if resp.Appid != nil {
|
||||
m["appId"] = *resp.Appid
|
||||
}
|
||||
if resp.TimeStamp != nil {
|
||||
m["timeStamp"] = *resp.TimeStamp
|
||||
}
|
||||
if resp.NonceStr != nil {
|
||||
m["nonceStr"] = *resp.NonceStr
|
||||
}
|
||||
if resp.Package != nil {
|
||||
m["package"] = *resp.Package
|
||||
}
|
||||
if resp.SignType != nil {
|
||||
m["signType"] = *resp.SignType
|
||||
}
|
||||
if resp.PaySign != nil {
|
||||
m["paySign"] = *resp.PaySign
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateWechatH5Order 创建微信H5支付订单
|
||||
@@ -237,8 +264,7 @@ func (w *WechatPayService) CreateWechatH5Order(ctx context.Context, amount float
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("微信支付订单创建失败: %v, 状态码: %d", err, result.Response.StatusCode)
|
||||
}
|
||||
// 返回预支付交易会话标识
|
||||
return resp, nil
|
||||
return jsapiRespToMap(resp), nil
|
||||
}
|
||||
|
||||
// CreateWechatOrder 创建微信支付订单(集成 APP、H5、小程序)
|
||||
|
||||
Reference in New Issue
Block a user