- 实现账号增删改查接口和逻辑 - 支持账号状态更新及状态历史记录功能 - 提供账号列表、历史和统计信息查询API - 实现账号轮询机制,支持按使用时间轮询获取账号 - 增加账号登录流程及批量登录功能,集成接码平台和平台API - 管理账号订单容量,支持容量检查与账号登录触发 - 提供账号池状态统计接口 - 账号历史记录查询支持多种变更类型文本展示 - 密码等敏感信息采用脱敏展示 - 完善日志记录和错误处理机制,保证业务稳定运行
87 lines
2.7 KiB
Go
87 lines
2.7 KiB
Go
package card_apple_order
|
||
|
||
import (
|
||
"context"
|
||
"fmt"
|
||
"time"
|
||
|
||
"github.com/gogf/gf/v2/net/gtrace"
|
||
"github.com/gogf/gf/v2/os/gctx"
|
||
|
||
"github.com/gogf/gf/v2/errors/gerror"
|
||
"github.com/gogf/gf/v2/frame/g"
|
||
"github.com/gogf/gf/v2/net/gclient"
|
||
"github.com/gogf/gf/v2/os/glog"
|
||
"github.com/gogf/gf/v2/os/gtime"
|
||
"github.com/gogf/gf/v2/text/gstr"
|
||
"github.com/gogf/gf/v2/util/gconv"
|
||
|
||
"kami/internal/consts"
|
||
"kami/internal/errHandler"
|
||
"kami/internal/model"
|
||
"kami/internal/model/entity"
|
||
"kami/utility/pool"
|
||
"kami/utility/utils"
|
||
)
|
||
|
||
// CallbackOrder 回调订单给第三方
|
||
func (h *sAppleOrder) CallbackOrder(ctx context.Context, data *entity.V1CardAppleRechargeInfo) (bool, error) {
|
||
timestamp := gtime.Now().Timestamp()
|
||
params := g.Map{
|
||
"attach": data.Attach,
|
||
"order_id": data.OrderNo,
|
||
"amount": data.ActualAmount,
|
||
"status": data.Status,
|
||
"remark": data.Remark,
|
||
"timestamp": timestamp,
|
||
"sign": utils.TmpEncrypt(data.Attach + data.OrderNo + gconv.String(timestamp)),
|
||
}
|
||
glog.Info(ctx, "回调参数:", params, "回调地址:", data.CallbackUrl)
|
||
client := gclient.New()
|
||
client.SetTimeout(30 * time.Second)
|
||
response := client.GetContent(ctx, data.CallbackUrl, params)
|
||
glog.Info(ctx, "回调结果:", response)
|
||
if gstr.ToLower(response) == "success" {
|
||
return true, nil
|
||
} else {
|
||
return false, gerror.NewCode(errHandler.HttpClientGetError, fmt.Sprintf("回调失败:%s", response))
|
||
}
|
||
}
|
||
|
||
func (h *sAppleOrder) CallBackOrderToUpstream(ctx context.Context, orderNo string) (err error) {
|
||
ctx, span := gtrace.NewSpan(ctx, "苹果回调")
|
||
defer span.End()
|
||
orderEntity, err := h.GetOneByOrderNo(ctx, orderNo, nil)
|
||
if err != nil {
|
||
return
|
||
}
|
||
err = pool.New(pool.AppleCardCallBack, 20).Add(gctx.GetInitCtx(), func(ctx context.Context) {
|
||
isCallbackSucceed := false
|
||
for i := 1; i < 4; i++ {
|
||
isOk, err2 := h.CallbackOrder(ctx, &orderEntity)
|
||
if isOk {
|
||
_ = h.AddHistory(ctx, &model.AppleCardRechargeHistoryInput{
|
||
OrderNo: orderEntity.OrderNo,
|
||
RechargeId: int(orderEntity.Id),
|
||
AccountID: orderEntity.AccountId,
|
||
Operation: consts.AppleRechargeOperationCallBackSuccess,
|
||
}, nil)
|
||
isCallbackSucceed = true
|
||
break
|
||
} else {
|
||
glog.Error(ctx, "回调上游失败,原因:\n", err2)
|
||
_ = h.AddHistory(ctx, &model.AppleCardRechargeHistoryInput{
|
||
OrderNo: orderEntity.OrderNo,
|
||
RechargeId: int(orderEntity.Id),
|
||
AccountID: orderEntity.AccountId,
|
||
Operation: consts.AppleRechargeOperationCallBackFailed,
|
||
Remark: fmt.Sprintf("第%d次回调失败,原因:回调接口返回失败", i),
|
||
}, nil)
|
||
}
|
||
time.Sleep(time.Duration(i*2) * time.Second)
|
||
}
|
||
_ = h.ModifyCallBackStatus(ctx, orderEntity.OrderNo, isCallbackSucceed, nil)
|
||
})
|
||
return
|
||
}
|