139 lines
4.8 KiB
Go
139 lines
4.8 KiB
Go
package httpcall
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"finclip-app-manager/infrastructure/config"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
//创建小程序、应用申请权限
|
|
const (
|
|
PAY_ADD_TYPE_APP = 1
|
|
PAY_ADD_TYPE_BINDING = 2
|
|
|
|
PAY_ID_STATUS_NO_USE = 1
|
|
PAY_ID_STATUS_USING = 2
|
|
PAY_ID_STATUS_EXPIRE = 3
|
|
)
|
|
|
|
type PayAddLimitReq struct {
|
|
Type int `json:"type"`
|
|
AccountId string `json:"accountId"`
|
|
BusinessId string `json:"businessId"`
|
|
BusinessName string `json:"businessName"`
|
|
}
|
|
type PayAddLimitRsp struct {
|
|
Errcode string `json:"errcode"`
|
|
Error string `json:"error"`
|
|
Data struct {
|
|
RightId string `json:"rightId"`
|
|
EndTime int64 `json:"endTime"`
|
|
} `json:"data"`
|
|
}
|
|
|
|
func (c *Client) PayAddLimit(ctx context.Context, req *PayAddLimitReq) (*PayAddLimitRsp, int, error) {
|
|
url := config.GetConfig().PayAddLimitHost + config.GetConfig().PayAddLimitURL
|
|
|
|
log.Infof("PayAddLimit url:%s,req:%+v", url, req)
|
|
|
|
rsp, err := c.Request(ctx).SetHeaders(c.getNewDefaultReqHeader()).SetBody(req).Post(url)
|
|
if err != nil {
|
|
log.Errorf("PayAddLimit err:%+v,status code:%+v", err, rsp)
|
|
return nil, http.StatusInternalServerError, err
|
|
}
|
|
if rsp.StatusCode() != http.StatusOK {
|
|
log.Errorf("PayAddLimit status code no 200 :%+v,boyd:%+v", rsp.StatusCode(), rsp.String())
|
|
return nil, rsp.StatusCode(), nil
|
|
}
|
|
rspInfo := PayAddLimitRsp{}
|
|
if err := json.Unmarshal(rsp.Body(), &rspInfo); err != nil {
|
|
log.Errorf("PayAddLimit json unmarshal err:%+v,rsp body:%+v", err, rsp.String())
|
|
return nil, rsp.StatusCode(), err
|
|
}
|
|
log.Infof("PayAddLimit rsp:%+v", rsp.String())
|
|
return &rspInfo, rsp.StatusCode(), nil
|
|
}
|
|
|
|
func (c *Client) PayUpdateLimit(ctx context.Context, req *PayAddLimitReq) (*PayAddLimitRsp, int, error) {
|
|
url := config.GetConfig().PayAddLimitHost + config.GetConfig().PayUpdateLimitURL
|
|
|
|
log.Infof("PayAddLimit url:%s,req:%+v", url, req)
|
|
|
|
rsp, err := c.Request(ctx).SetHeaders(c.getNewDefaultReqHeader()).SetBody(req).Post(url)
|
|
if err != nil {
|
|
log.Errorf("PayAddLimit err:%+v,status code:%+v", err, rsp)
|
|
return nil, http.StatusInternalServerError, err
|
|
}
|
|
if rsp.StatusCode() != http.StatusOK {
|
|
log.Errorf("PayAddLimit status code no 200 :%+v,boyd:%+v", rsp.StatusCode(), rsp.String())
|
|
return nil, rsp.StatusCode(), nil
|
|
}
|
|
rspInfo := PayAddLimitRsp{}
|
|
if err := json.Unmarshal(rsp.Body(), &rspInfo); err != nil {
|
|
log.Errorf("PayAddLimit json unmarshal err:%+v,rsp body:%+v", err, rsp.String())
|
|
return nil, rsp.StatusCode(), err
|
|
}
|
|
log.Infof("PayAddLimit rsp:%+v", rsp.String())
|
|
return &rspInfo, rsp.StatusCode(), nil
|
|
}
|
|
|
|
type PayCheckIdStatusRsp struct {
|
|
Errcode string `json:"errcode"`
|
|
Error string `json:"error"`
|
|
Data struct {
|
|
Status int `json:"status"`
|
|
} `json:"data"`
|
|
}
|
|
|
|
func (c *Client) PayCheckIdStatus(ctx context.Context, id string) (int, int, error) {
|
|
url := fmt.Sprintf(config.GetConfig().PayAddLimitHost+config.GetConfig().PayCheckIdStatusURL+"?businessId=%s", id)
|
|
log.Infof("PayCheckIdStatus url:%s", url)
|
|
rsp, err := c.Request(ctx).SetHeaders(c.getNewDefaultReqHeader()).Get(url)
|
|
if err != nil {
|
|
log.Errorf("PayCheckIdStatus err:%+v,status code:%+v", err, rsp)
|
|
return 0, http.StatusInternalServerError, err
|
|
}
|
|
if rsp.StatusCode() != http.StatusOK {
|
|
log.Errorf("PayCheckIdStatus status code no 200 :%+v,boyd:%+v", rsp.StatusCode(), rsp.String())
|
|
return 0, rsp.StatusCode(), errors.New("PayCheckIdStatus status code no ok")
|
|
}
|
|
rspInfo := PayCheckIdStatusRsp{}
|
|
if err := json.Unmarshal(rsp.Body(), &rspInfo); err != nil {
|
|
log.Errorf("PayCheckIdStatus json unmarshal err:%+v,rsp body:%+v", err, rsp.String())
|
|
return 0, rsp.StatusCode(), err
|
|
}
|
|
log.Infof("PayCheckIdStatus rsp:%+v", rsp.String())
|
|
return rspInfo.Data.Status, rsp.StatusCode(), nil
|
|
}
|
|
|
|
type PayFixOldDataReq struct {
|
|
OrganId string `json:"organId"`
|
|
Type int `json:"type"`
|
|
BusinessId string `json:"businessId"`
|
|
BusinessName string `json:"businessName"`
|
|
CreateTime int64 `json:"createTime"`
|
|
}
|
|
|
|
func (c *Client) PayFixOldData(ctx context.Context, req *PayFixOldDataReq) (int, error) {
|
|
url := fmt.Sprintf(config.GetConfig().PayAddLimitHost + config.GetConfig().PayFixOldDataURL)
|
|
rsp, err := c.Request(ctx).SetHeaders(c.getNewDefaultReqHeader()).SetBody(req).Post(url)
|
|
if err != nil {
|
|
log.Errorf("PayFixOldData err:%+v,status code:%+v", err, rsp)
|
|
return http.StatusInternalServerError, err
|
|
}
|
|
if rsp.StatusCode() != http.StatusOK {
|
|
log.Errorf("PayFixOldData status code no 200 :%+v,boyd:%+v", rsp.StatusCode(), rsp.String())
|
|
return rsp.StatusCode(), errors.New("PayCheckIdStatus status code no ok")
|
|
}
|
|
rspInfo := PayCheckIdStatusRsp{}
|
|
if err := json.Unmarshal(rsp.Body(), &rspInfo); err != nil {
|
|
log.Errorf("PayFixOldData json unmarshal err:%+v,rsp body:%+v", err, rsp.String())
|
|
return rsp.StatusCode(), err
|
|
}
|
|
//log.Infof("PayFixOldData rsp:%+v", rsp.String())
|
|
return rsp.StatusCode(), nil
|
|
}
|