- 新增 Camel Oil 客户端结构体及单例初始化方法 - 实现发送验证码请求方法 SendCaptcha,支持手机号验证和错误处理 - 实现验证码登录方法 LoginWithCaptcha,返回登录令牌并记录日志 - apple 模块新增空的 Redeem 方法占位,添加 context 参数以支持未来实现 - 优化 apple 客户端代码格式,引入 context 包支持请求上下文管理
81 lines
2.0 KiB
Go
81 lines
2.0 KiB
Go
package camel_oil
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"github.com/gogf/gf/v2/net/gclient"
|
|
"github.com/gogf/gf/v2/os/glog"
|
|
"sync"
|
|
)
|
|
|
|
type Client struct {
|
|
Client *gclient.Client
|
|
}
|
|
|
|
var client *Client
|
|
|
|
func NewClient() *Client {
|
|
sync.OnceFunc(func() {
|
|
client = &Client{
|
|
Client: gclient.New(),
|
|
}
|
|
})()
|
|
return client
|
|
}
|
|
|
|
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: "17862666120",
|
|
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
|
|
}
|