-
Notifications
You must be signed in to change notification settings - Fork 0
/
riskcontrol.go
60 lines (49 loc) · 1.72 KB
/
riskcontrol.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
package riskcontrol
import (
"fmt"
"github.com/36625090/wechat/miniprogram/context"
"github.com/36625090/wechat/util"
)
const (
getUserRiskRankURL = "https://api.weixin.qq.com/wxa/getuserriskrank?access_token=%s"
)
// RiskControl 安全风控
type RiskControl struct {
*context.Context
}
// NewRiskControl init
func NewRiskControl(ctx *context.Context) *RiskControl {
return &RiskControl{ctx}
}
// UserRiskRankRequest 获取用户安全等级请求
type UserRiskRankRequest struct {
AppID string `json:"appid"` // 小程序 app id
OpenID string `json:"openid"` // 用户的 openid
Scene uint8 `json:"scene"` // 场景值,0:注册,1:营销作弊
ClientIP string `json:"client_ip"` // 用户访问源ip
Mobile string `json:"mobile_no"` // 用户手机号
Email string `json:"email_address"` // 用户邮箱地址
ExtendedInfo string `json:"extended_info"` // 额外补充信息
IsTest bool `json:"is_test"` // false:正式调用,true:测试调用
}
// UserRiskRank 用户安全等级
type UserRiskRank struct {
util.CommonError
UnionID int64 `json:"union_id"` // 唯一请求标识
RiskRank uint8 `json:"risk_rank"` // 用户风险等级
}
// GetUserRiskRank 根据提交的用户信息数据获取用户的安全等级 risk_rank,无需用户授权。
func (riskControl *RiskControl) GetUserRiskRank(in *UserRiskRankRequest) (res UserRiskRank, err error) {
accessToken, err := riskControl.GetAccessToken()
if err != nil {
return
}
uri := fmt.Sprintf(getUserRiskRankURL, accessToken)
response, err := util.PostJSON(uri, in)
if err != nil {
return
}
// 使用通用方法返回错误
err = util.DecodeWithError(response, &res, "GetUserRiskRank")
return
}