优化小程序登录流程,增加用户协议和隐私政策的勾选机制,确保用户主动同意后方可登录,符合审核要求。同时,增强错误处理逻辑,提升用户体验和系统稳定性。新增用户协议和隐私政策页面,更新相关样式以改善界面交互。
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"soul-api/internal/config"
|
||||
|
||||
"github.com/ArtisanCloud/PowerLibs/v3/object"
|
||||
fundAppRequest "github.com/ArtisanCloud/PowerWeChat/v3/src/payment/fundApp/request"
|
||||
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/transfer/request"
|
||||
)
|
||||
|
||||
@@ -136,3 +137,83 @@ func GenerateTransferDetailNo() string {
|
||||
random := now.UnixNano() % 1000000
|
||||
return fmt.Sprintf("WDD%s%06d", timestamp, random)
|
||||
}
|
||||
|
||||
// FundAppTransferParams 单笔转账(FundApp 发起转账)参数
|
||||
type FundAppTransferParams struct {
|
||||
OutBillNo string // 商户单号(唯一,回调时 out_bill_no 即此值,建议存到 withdrawal.detail_no)
|
||||
OpenID string
|
||||
UserName string // 可选
|
||||
Amount int // 分
|
||||
Remark string
|
||||
NotifyURL string
|
||||
TransferSceneId string // 可选,如 "1005"
|
||||
}
|
||||
|
||||
// FundAppTransferResult 单笔转账结果
|
||||
type FundAppTransferResult struct {
|
||||
OutBillNo string
|
||||
TransferBillNo string
|
||||
State string
|
||||
}
|
||||
|
||||
// InitiateTransferByFundApp 发起商家转账到零钱(PowerWeChat FundApp.TransferBills 单笔接口)
|
||||
// 与 TransferBatch 不同,此为 /v3/fund-app/mch-transfer/transfer-bills 单笔发起,回调仍为 MCHTRANSFER.BILL.FINISHED,解密后 out_bill_no 即本接口传入的 OutBillNo
|
||||
func InitiateTransferByFundApp(params FundAppTransferParams) (*FundAppTransferResult, error) {
|
||||
if paymentApp == nil || paymentApp.FundApp == nil {
|
||||
return nil, fmt.Errorf("支付/转账未初始化,请先调用 wechat.Init")
|
||||
}
|
||||
req := &fundAppRequest.RequestTransferBills{
|
||||
Appid: cfg.WechatAppID,
|
||||
OutBillNo: params.OutBillNo,
|
||||
TransferSceneId: params.TransferSceneId,
|
||||
Openid: params.OpenID,
|
||||
UserName: params.UserName,
|
||||
TransferAmount: params.Amount,
|
||||
TransferRemark: params.Remark,
|
||||
NotifyUrl: params.NotifyURL,
|
||||
}
|
||||
if req.NotifyUrl == "" && cfg.WechatTransferURL != "" {
|
||||
req.NotifyUrl = cfg.WechatTransferURL
|
||||
}
|
||||
ctx := context.Background()
|
||||
resp, err := paymentApp.FundApp.TransferBills(ctx, req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("发起转账失败: %w", err)
|
||||
}
|
||||
if resp == nil {
|
||||
return nil, fmt.Errorf("转账返回为空")
|
||||
}
|
||||
// 微信返回 4xx 时 body 可能被解析到 resp,需根据 code 或 out_bill_no 判断是否成功
|
||||
if resp.Code != "" {
|
||||
msg := resp.Message
|
||||
if msg == "" {
|
||||
msg = resp.Code
|
||||
}
|
||||
return nil, fmt.Errorf("微信接口报错: %s", msg)
|
||||
}
|
||||
if resp.OutBillNo == "" {
|
||||
return nil, fmt.Errorf("微信未返回商户单号,可能请求被拒绝(如IP未加入白名单)")
|
||||
}
|
||||
result := &FundAppTransferResult{
|
||||
OutBillNo: resp.OutBillNo,
|
||||
TransferBillNo: resp.TransferBillNo,
|
||||
State: resp.State,
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// QueryTransferByOutBill 按商户单号查询单笔转账结果(FundApp 接口,用于 sync)
|
||||
func QueryTransferByOutBill(outBillNo string) (state, transferBillNo, failReason string, err error) {
|
||||
if paymentApp == nil || paymentApp.FundApp == nil {
|
||||
return "", "", "", fmt.Errorf("支付/转账未初始化")
|
||||
}
|
||||
ctx := context.Background()
|
||||
resp, err := paymentApp.FundApp.QueryOutBill(ctx, outBillNo)
|
||||
if err != nil {
|
||||
return "", "", "", err
|
||||
}
|
||||
if resp == nil {
|
||||
return "", "", "", nil
|
||||
}
|
||||
return resp.State, resp.TransferBillNo, resp.FailReason, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user