174 lines
7.3 KiB
Go
174 lines
7.3 KiB
Go
package transfer
|
||
|
||
import "encoding/json"
|
||
|
||
type TransferBillStatus string
|
||
|
||
func (e TransferBillStatus) Ptr() *TransferBillStatus {
|
||
return &e
|
||
}
|
||
|
||
// ACCEPTED: 转账已受理
|
||
// PROCESSING: 转账锁定资金中。如果一直停留在该状态,建议检查账户余额是否足够,如余额不足,可充值后再原单重试。
|
||
// WAIT_USER_CONFIRM: 待收款用户确认,可拉起微信收款确认页面进行收款确认
|
||
// TRANSFERING: 转账中,可拉起微信收款确认页面再次重试确认收款
|
||
// SUCCESS: 转账成功
|
||
// FAIL: 转账失败
|
||
// CANCELING: 商户撤销请求受理成功,该笔转账正在撤销中
|
||
// CANCELLED: 转账撤销完成
|
||
const (
|
||
TRANSFERBILLSTATUS_ACCEPTED TransferBillStatus = "ACCEPTED"
|
||
TRANSFERBILLSTATUS_PROCESSING TransferBillStatus = "PROCESSING"
|
||
TRANSFERBILLSTATUS_WAIT_USER_CONFIRM TransferBillStatus = "WAIT_USER_CONFIRM"
|
||
TRANSFERBILLSTATUS_TRANSFERING TransferBillStatus = "TRANSFERING"
|
||
TRANSFERBILLSTATUS_SUCCESS TransferBillStatus = "SUCCESS"
|
||
TRANSFERBILLSTATUS_FAIL TransferBillStatus = "FAIL"
|
||
TRANSFERBILLSTATUS_CANCELING TransferBillStatus = "CANCELING"
|
||
TRANSFERBILLSTATUS_CANCELLED TransferBillStatus = "CANCELLED"
|
||
)
|
||
|
||
var TransferBillStatusMap = map[TransferBillStatus]string{
|
||
TRANSFERBILLSTATUS_ACCEPTED: "转账已受理",
|
||
TRANSFERBILLSTATUS_PROCESSING: "转账锁定资金中,建议检查账户余额是否足够",
|
||
TRANSFERBILLSTATUS_WAIT_USER_CONFIRM: "待收款用户确认",
|
||
TRANSFERBILLSTATUS_TRANSFERING: "转账中",
|
||
TRANSFERBILLSTATUS_SUCCESS: "转账成功",
|
||
TRANSFERBILLSTATUS_FAIL: "转账失败",
|
||
TRANSFERBILLSTATUS_CANCELING: "转账正在撤销中",
|
||
TRANSFERBILLSTATUS_CANCELLED: "转账撤销完成",
|
||
}
|
||
|
||
func (s TransferBillStatus) GetValue() string {
|
||
return string(s)
|
||
}
|
||
|
||
func (s TransferBillStatus) GetText() string {
|
||
if t, ok := TransferBillStatusMap[s]; ok {
|
||
return t
|
||
}
|
||
return "未知状态"
|
||
}
|
||
|
||
type TransferToUserRequest struct {
|
||
Appid *string `json:"appid,omitempty"`
|
||
OutBillNo *string `json:"out_bill_no,omitempty"`
|
||
TransferSceneId *string `json:"transfer_scene_id,omitempty"`
|
||
Openid *string `json:"openid,omitempty"`
|
||
UserName *string `json:"user_name,omitempty"`
|
||
TransferAmount *int64 `json:"transfer_amount,omitempty"`
|
||
TransferRemark *string `json:"transfer_remark,omitempty"`
|
||
NotifyUrl *string `json:"notify_url,omitempty"`
|
||
UserRecvPerception *string `json:"user_recv_perception,omitempty"`
|
||
TransferSceneReportInfos []TransferSceneReportInfo `json:"transfer_scene_report_infos,omitempty"`
|
||
}
|
||
|
||
type TransferSceneReportInfo struct {
|
||
InfoType *string `json:"info_type,omitempty"`
|
||
InfoContent *string `json:"info_content,omitempty"`
|
||
}
|
||
|
||
type TransferToUserResponse struct {
|
||
OutBillNo *string `json:"out_bill_no,omitempty"` // 商户单号
|
||
TransferBillNo *string `json:"transfer_bill_no,omitempty"` // 微信转账单号 string(64)
|
||
CreateTime *string `json:"create_time,omitempty"` // 单据创建时间 单据受理成功时返回 格式为yyyy-MM-DDThh:mm:ss+TIMEZONE
|
||
State *TransferBillStatus `json:"state,omitempty"` // 商家转账订单状态
|
||
PackageInfo *string `json:"package_info,omitempty"` // 跳转领取页面的package信息
|
||
}
|
||
|
||
type CancelTransferResponse struct {
|
||
OutBillNo *string `json:"out_bill_no,omitempty"`
|
||
TransferBillNo *string `json:"transfer_bill_no,omitempty"`
|
||
State *string `json:"state,omitempty"` // 【单据状态】 CANCELING: 撤销中;CANCELLED:已撤销
|
||
UpdateTime *string `json:"update_time,omitempty"`
|
||
}
|
||
|
||
type CancelTransferRequest struct {
|
||
OutBillNo *string `json:"out_bill_no,omitempty"`
|
||
}
|
||
|
||
func (o *CancelTransferRequest) MarshalJSON() ([]byte, error) {
|
||
type Alias CancelTransferRequest
|
||
a := &struct {
|
||
OutBillNo *string `json:"out_bill_no,omitempty"`
|
||
*Alias
|
||
}{
|
||
// 序列化时移除非 Body 字段
|
||
OutBillNo: nil,
|
||
Alias: (*Alias)(o),
|
||
}
|
||
return json.Marshal(a)
|
||
}
|
||
|
||
type GetTransferBillByOutNoRequest struct {
|
||
OutBillNo *string `json:"out_bill_no,omitempty"`
|
||
}
|
||
|
||
func (o *GetTransferBillByOutNoRequest) MarshalJSON() ([]byte, error) {
|
||
type Alias GetTransferBillByOutNoRequest
|
||
a := &struct {
|
||
OutBillNo *string `json:"out_bill_no,omitempty"`
|
||
*Alias
|
||
}{
|
||
// 序列化时移除非 Body 字段
|
||
OutBillNo: nil,
|
||
Alias: (*Alias)(o),
|
||
}
|
||
return json.Marshal(a)
|
||
}
|
||
|
||
type TransferBillEntity struct {
|
||
MchId *string `json:"mch_id,omitempty"` // 商户号
|
||
OutBillNo *string `json:"out_bill_no,omitempty"` // 商户单号
|
||
TransferBillNo *string `json:"transfer_bill_no,omitempty"` // 微信单号
|
||
Appid *string `json:"appid,omitempty"` // 应用id
|
||
State *TransferBillStatus `json:"state,omitempty"` // 商家转账订单状态
|
||
TransferAmount *int64 `json:"transfer_amount,omitempty"` // 转账总金额,单位为“分”
|
||
TransferRemark *string `json:"transfer_remark,omitempty"` // 转账备注
|
||
FailReason *string `json:"fail_reason,omitempty"` // 单已失败或者已退资金时,会返回订单失败原因 https://pay.weixin.qq.com/doc/v3/merchant/4013774966
|
||
Openid *string `json:"openid,omitempty"` // 用户在商户appid下的唯一标识
|
||
UserName *string `json:"user_name,omitempty"` // 收款用户姓名
|
||
CreateTime *string `json:"create_time,omitempty"` // 单据创建时间
|
||
UpdateTime *string `json:"update_time,omitempty"` // 最后一次状态变更时间
|
||
}
|
||
|
||
type GetTransferBillByNoRequest struct {
|
||
TransferBillNo *string `json:"transfer_bill_no,omitempty"`
|
||
}
|
||
|
||
func (o *GetTransferBillByNoRequest) MarshalJSON() ([]byte, error) {
|
||
type Alias GetTransferBillByNoRequest
|
||
a := &struct {
|
||
TransferBillNo *string `json:"transfer_bill_no,omitempty"`
|
||
*Alias
|
||
}{
|
||
// 序列化时移除非 Body 字段
|
||
TransferBillNo: nil,
|
||
Alias: (*Alias)(o),
|
||
}
|
||
return json.Marshal(a)
|
||
}
|
||
|
||
type TransferBillNotify struct {
|
||
OutBillNo *string `json:"out_bill_no,omitempty"`
|
||
TransferBillNo *string `json:"transfer_bill_no,omitempty"`
|
||
State *TransferBillStatus `json:"state,omitempty"`
|
||
MchId *string `json:"mch_id,omitempty"`
|
||
TransferAmount *int64 `json:"transfer_amount,omitempty"`
|
||
Openid *string `json:"openid,omitempty"`
|
||
FailReason *string `json:"fail_reason,omitempty"`
|
||
CreateTime *string `json:"create_time,omitempty"`
|
||
UpdateTime *string `json:"update_time,omitempty"`
|
||
}
|
||
|
||
// TransferErr {"code":"INVALID_REQUEST","message":"对应单号已超出重试期;请查单确认后决定是否换单请求"}
|
||
type TransferErr struct {
|
||
Code string `json:"code,omitempty"`
|
||
Message string `json:"message,omitempty"`
|
||
}
|
||
|
||
func BuildTransferErr(body []byte) (*TransferErr, error) {
|
||
ret := &TransferErr{}
|
||
err := json.Unmarshal(body, &ret)
|
||
return ret, err
|
||
}
|