- 实现账号增删改查接口和逻辑 - 支持账号状态更新及状态历史记录功能 - 提供账号列表、历史和统计信息查询API - 实现账号轮询机制,支持按使用时间轮询获取账号 - 增加账号登录流程及批量登录功能,集成接码平台和平台API - 管理账号订单容量,支持容量检查与账号登录触发 - 提供账号池状态统计接口 - 账号历史记录查询支持多种变更类型文本展示 - 密码等敏感信息采用脱敏展示 - 完善日志记录和错误处理机制,保证业务稳定运行
157 lines
4.2 KiB
Go
157 lines
4.2 KiB
Go
package camel_oil_api
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"github.com/gogf/gf/v2/net/gclient"
|
|
"github.com/gogf/gf/v2/os/glog"
|
|
)
|
|
|
|
type Client struct {
|
|
Client *gclient.Client
|
|
}
|
|
|
|
func NewClient() *Client {
|
|
return &Client{
|
|
Client: gclient.New(),
|
|
}
|
|
}
|
|
|
|
func (c *Client) SendCaptcha(ctx context.Context, phone string) (bool, error) {
|
|
req := struct {
|
|
OpenId string `json:"openId"`
|
|
Phone string `json:"phone"`
|
|
CouponStatus string `json:"couponStatus"`
|
|
Channel string `json:"channel"`
|
|
}{
|
|
OpenId: "app2511181557205741495",
|
|
Phone: phone,
|
|
CouponStatus: "unused",
|
|
Channel: "app",
|
|
}
|
|
resp, err := c.Client.Post(ctx, "https://recharge3.bac365.com/camel_wechat_mini_oil_server/refueling/getUserCouponList", req)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
respStruct := struct {
|
|
Code string `json:"code"`
|
|
Message string `json:"message"`
|
|
}{}
|
|
err = json.Unmarshal(resp.ReadAll(), &respStruct)
|
|
return respStruct.Code == "success", err
|
|
}
|
|
|
|
func (c *Client) LoginWithCaptcha(ctx context.Context, phone string, code string) (string, error) {
|
|
req := struct {
|
|
Phone string `json:"phone"`
|
|
Codes string `json:"codes"`
|
|
Channel string `json:"channel"`
|
|
}{
|
|
Phone: phone,
|
|
Codes: code,
|
|
Channel: "app",
|
|
}
|
|
resp, err := c.Client.Post(ctx, "https://recharge3.bac365.com/camel_wechat_mini_oil_server/loginApp", req)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
glog.Info(ctx, "登录", req, resp.ReadAllString())
|
|
respStruct := struct {
|
|
LoginUser struct {
|
|
UserIdApp string `json:"userIdApp"`
|
|
Phone string `json:"phone"`
|
|
UserIdCamel string `json:"userIdCamel"`
|
|
LoginTime string `json:"loginTime"`
|
|
ExpireTime string `json:"expireTime"`
|
|
Ipaddr string `json:"ipaddr"`
|
|
}
|
|
Code string `json:"code"`
|
|
Message string `json:"message"`
|
|
Token string `json:"token"`
|
|
}{}
|
|
err = json.Unmarshal(resp.ReadAll(), &respStruct)
|
|
return respStruct.Token, err
|
|
}
|
|
|
|
func (c *Client) CreateOrder(ctx context.Context, phone, token string, amount float64) (orderId string, payUrl string, err error) {
|
|
//c.Client.SetHeader("Authorization", token)
|
|
resp, err := c.Client.Post(ctx, "https://recharge3.bac365.com/camel_wechat_mini_oil_server/eCardMall/wechatCardGoods", struct {
|
|
Channel string `json:"channel"`
|
|
}{
|
|
Channel: "app",
|
|
})
|
|
if err != nil {
|
|
return "", "", err
|
|
}
|
|
queryRespStruct := struct {
|
|
Code string `json:"code"`
|
|
Goods []struct {
|
|
GoodId string `json:"goodId"`
|
|
GoodName string `json:"goodName"`
|
|
Denomination float64 `json:"denomination"`
|
|
GoodPrice float64 `json:"goodPrice"`
|
|
Validity int `json:"validity"`
|
|
ImgUrl string `json:"imgUrl"`
|
|
Status string `json:"status"`
|
|
} `json:"goods"`
|
|
}{}
|
|
if err = json.Unmarshal(resp.ReadAll(), &queryRespStruct); err != nil {
|
|
return "", "", err
|
|
}
|
|
goodId := ""
|
|
for _, good := range queryRespStruct.Goods {
|
|
if good.Denomination == amount {
|
|
goodId = good.GoodId
|
|
break
|
|
}
|
|
}
|
|
if goodId == "" {
|
|
return "", "", errors.New("当前金额不支持")
|
|
}
|
|
//遍历 100次
|
|
for i := 0; i < 100; i++ {
|
|
req := struct {
|
|
BodyStr string `json:"bodyStr"`
|
|
Channel string `json:"channel"`
|
|
Yanqian bool `json:"yanqian"`
|
|
}{
|
|
BodyStr: "",
|
|
Channel: "app",
|
|
Yanqian: true,
|
|
}
|
|
resp, err = c.Client.Post(ctx, "https://recharge3.bac365.com/camel_wechat_mini_oil_server/eCardMall/createShoppingOrder", req)
|
|
if err != nil {
|
|
return "", "", err
|
|
}
|
|
glog.Info(ctx, "登录", req, resp.ReadAllString())
|
|
respStruct := struct {
|
|
Code string `json:"code"`
|
|
Message string `json:"message"`
|
|
OrderRes struct {
|
|
Body string `json:"body"`
|
|
} `json:"orderRes,omitempty"`
|
|
OrderId string `json:"orderid,omitempty"`
|
|
}{}
|
|
err = json.Unmarshal(resp.ReadAll(), &respStruct)
|
|
if respStruct.Code == "limit" {
|
|
continue
|
|
}
|
|
if respStruct.Code == "auth_error" {
|
|
return "", "", errors.New("auth_error")
|
|
}
|
|
return respStruct.OrderId, respStruct.OrderRes.Body, err
|
|
}
|
|
return "", "", errors.New("创建订单超时")
|
|
}
|
|
|
|
// QueryOrder 查询对应订单
|
|
func (c *Client) QueryOrder(ctx context.Context, phone, token, orderId string) (status bool, err error) {
|
|
//req := struct {
|
|
// OrderId string `json:"orderId"`
|
|
//}{
|
|
// OrderId: orderId,
|
|
//}
|
|
return false, nil
|
|
}
|