-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsign.go
227 lines (204 loc) · 5.92 KB
/
sign.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
package yunzhanghu
import (
"context"
"net/http"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
)
const (
SIGN_CERT_TYPE_IDCARD = 0 //身份证
SIGN_CERT_TYPE_HK_PASSPORT = 2 //港澳居民来往内地通行证
SIGN_CERT_TYPE_PASSPORT = 3 //护照
SIGN_CERT_TYPE_TW_PASSPORT = 5 //台湾居民来往大陆通行证
)
const (
SIGN_STATUS_NO = 0 //未签约
SIGN_STATUS_YES = 1 //已签约
SIGN_STATUS_CANCEL = 2 //已解约
SIGN_STATUS_NOT_FOUND = 9 //不存在签约关系
)
const (
h5PreSignURI = "/api/sdk/v1/presign"
)
type (
reqH5PreSign struct {
DealerID string `json:"dealer_id"` // 商户代码
BrokerID string `json:"broker_id"` // 综合服务主体 ID
RealName string `json:"real_name"` // 身份证姓名
IDCard string `json:"id_card"` // 身份证号码
CertificateType int `json:"certificate_type"` // 证件类型
}
H5PreSignData struct {
Uid string `json:"uid"`
Token string `json:"token"`
Status int64 `json:"status"`
}
retH5PreSign struct {
CommonResponse
Data H5PreSignData `json:"data"`
}
)
func (y *Yunzhanghu) H5PreSign(ctx context.Context, realName, idCard string, certType int) (*H5PreSignData, error) {
var (
input = &reqH5PreSign{
DealerID: y.Dealer,
BrokerID: y.Broker,
RealName: realName,
IDCard: idCard,
CertificateType: certType,
}
output = new(retH5PreSign)
apiName = "H5预申请签约"
)
responseBytes, err := y.postForm(ctx, h5PreSignURI, apiName, input)
if err != nil {
return nil, err
}
if err = y.decodeWithError(responseBytes, output, apiName); err != nil {
return nil, err
}
return &output.Data, nil
}
const (
h5SignURI = "/api/sdk/v1/sign/h5"
)
type (
reqH5Sign struct {
Token string `json:"token"` // H5 签约 token
Color string `json:"color"` // H5 页面主题颜色
URL string `json:"url"` // 回调 url 地址
RedirectURL string `json:"redirect_url"` // 跳转 url
}
H5SignData struct {
URL string `json:"url"` //h5 签约页面 url
}
retH5Sign struct {
CommonResponse
Data H5SignData `json:"data"`
}
)
func (y *Yunzhanghu) H5Sign(ctx context.Context, token, color string) (*H5SignData, error) {
var (
input = &reqH5Sign{
Token: token,
Color: color,
URL: y.H5SignNotifyUrl,
RedirectURL: y.H5SignRedirectURL,
}
output = new(retH5Sign)
apiName = "H5签约"
)
responseBytes, err := y.getJson(ctx, h5SignURI, apiName, input)
if err != nil {
return nil, err
}
if err = y.decodeWithError(responseBytes, output, apiName); err != nil {
return nil, err
}
return &output.Data, nil
}
const (
h5SignStatusURI = "/api/sdk/v1/sign/user/status"
)
type (
reqH5SignStatus struct {
DealerId string `json:"dealer_id"` // 商户代码(必填)
BrokerId string `json:"broker_id"` // 经纪公司(必填)
RealName string `json:"real_name"` // 姓名(必填)
IdCard string `json:"id_card"` // 身份证(必填)
}
H5SignStatusData struct {
SignedAt string `json:"signed_at"` // 2020-07-05 15:15:15
Status int64 `json:"status"` // 1
}
retH5SignStatus struct {
CommonResponse
Data H5SignStatusData `json:"data"`
}
)
func (y *Yunzhanghu) H5SignStatus(ctx context.Context, realName, idCard string) (*H5SignStatusData, error) {
var (
input = &reqH5SignStatus{
DealerId: y.Dealer,
BrokerId: y.Broker,
RealName: realName,
IdCard: idCard,
}
output = new(retH5SignStatus)
apiName = "获取用户签约状态"
)
responseBytes, err := y.getJson(ctx, h5SignStatusURI, apiName, input)
if err != nil {
return nil, err
}
if err = y.decodeWithError(responseBytes, output, apiName); err != nil {
return nil, err
}
return &output.Data, nil
}
const h5SignReleaseURI = "/api/sdk/v1/sign/release"
type (
reqSignRelease struct {
DealerID string `json:"dealer_id"` // 商户代码
BrokerID string `json:"broker_id"` // 综合服务主体 ID
RealName string `json:"real_name"` // 身份证姓名
IDCard string `json:"id_card"` // 身份证号码
CertificateType int `json:"certificate_type"` // 证件类型
}
SignReleaseData struct {
status string `json:"status"`
}
retSignRelease struct {
CommonResponse
Data SignReleaseData `json:"data"`
}
)
//H5 对接测试解约接口
func (y *Yunzhanghu) H5SignRelease(ctx context.Context, realName, idCard string, certType int) (*SignReleaseData, error) {
var (
input = &reqSignRelease{
DealerID: y.Dealer,
BrokerID: y.Broker,
RealName: realName,
IDCard: idCard,
CertificateType: certType,
}
output = new(retSignRelease)
apiName = "H5测试解约接口"
)
responseBytes, err := y.postForm(ctx, h5SignReleaseURI, apiName, input)
if err != nil {
return nil, err
}
if err = y.decodeWithError(responseBytes, output, apiName); err != nil {
return nil, err
}
return &output.Data, nil
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
type H5SignNotify struct {
BrokerID string `json:"broker_id"` // yiyun
DealerID string `json:"dealer_id"` // 01720374
IDCard string `json:"id_card"` // 360232199009115318
Phone string `json:"phone"` //
RealName string `json:"real_name"` // 王小明
}
func (y *Yunzhanghu) H5SignCallbackHandler(ctx *gin.Context) {
var resp *CallbackResponse
if err := ctx.MustBindWith(&resp, binding.FormPost); err != nil || resp == nil || resp.Data == "" {
ctx.String(http.StatusOK, RESP_STR_FAILD)
return
}
var h5SignResp *H5SignNotify
err := DecryptB64TriDesTo(resp.Data, []byte(y.DesKey), &h5SignResp)
if err != nil {
ctx.String(http.StatusOK, RESP_STR_FAILD)
return
}
ok := y.H5SignNotifyCallback(ctx, h5SignResp)
if !ok {
ctx.String(http.StatusOK, RESP_STR_FAILD)
return
}
ctx.String(http.StatusOK, RESP_STR_SUCCESS)
}