Skip to content

Commit 68dc9ab

Browse files
author
Javen
committed
代商家注册小程序与试用小程序相关api添加,
1 parent 2d48310 commit 68dc9ab

File tree

9 files changed

+376
-71
lines changed

9 files changed

+376
-71
lines changed

README.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#### 2.1: 引入
1919
go get -u github.com/l306287405/wechat3rd@master
2020
or
21-
go get -u github.com/l306287405/[email protected].5 (请选择最新版本)
21+
go get -u github.com/l306287405/[email protected].6 (请选择最新版本)
2222
v1.6.0版本开始Service提供的所有方法仅在resp返回对象中提供错误信息
2323

2424
#### 2.2: 使用NewService方法来创建一个service
@@ -137,7 +137,12 @@
137137

138138
c.Ctx.HTML("授权成功")
139139

140-
### 4. API实现
140+
### 3. API实现
141+
**注意:**
142+
调用以下api前,请详细查询相关文档,通常都必备令牌参数,分以下两种:
143+
* component_access_token: 指的是"第三方平台令牌",通常对应方法不需要使用者提供,如有特殊需要则调用service的Token()方法获取.
144+
* authorizer_access_token: 指的是"第三方平台接口调用令牌",通常对应方法需要使用者提供授权小程序的授权token.
145+
141146
#### openApi管理
142147
* ClearQuota: 清空api的调用quota
143148
* QuotaGet: 查询openApi调用quota
@@ -149,13 +154,17 @@
149154
* ModifyWxaJumpDomain: 设置第三方平台业务域名
150155

151156
#### 小程序用户隐私保护指引
152-
以下接口注意:accessToken(authorizerAccessToken)为授权方token!!!
153157
* SetPrivacySetting: 设置小程序用户隐私保护指引
154158
* GetPrivacySetting: 查询小程序用户隐私保护指引
155159
* UploadPrivacyExtFile: 上传小程序用户隐私保护指引
156160

157161
#### 授权相关接口:
158-
* ServeHTTP: 处理消息与事件接收URL的推送 例如:获取component_verify_ticket,授权变更通知推送, 小程序审核, 类目审核等结果推送
162+
* ServeHTTP: 处理消息与事件接收URL的推送 例如:
163+
* 获取component_verify_ticket
164+
* 授权变更通知推送
165+
* 小程序审核
166+
* 类目审核
167+
* 等等
159168
* ApiStartPushTicket: 启动ticket推送服务
160169
* AccessTokenServer.Token: 获取令牌
161170
* Token: 获取第三方平台的token
@@ -176,13 +185,21 @@
176185
* OpenUnbind: 将公众号/小程序从开放平台帐号下解绑
177186
* OpenGet: 获取公众号/小程序所绑定的开放平台帐号
178187

188+
#### 代商家注册小程序
189+
* FastRegisterOrgWeapp: 快速注册企业小程序
190+
* QueryOrgWeapp: 查询注册企业创建任务状态
191+
* FastRegisterPersonalWeapp: 快速注册个人小程序
192+
* QueryPersonalWeapp: 查询个人小程序创建任务状态
193+
194+
#### 创建试用小程序
195+
* FastRegisterBetaWeapp: 创建试用小程序
196+
* VerifyBetaWeapp: 试用小程序快速认证
197+
* SetBetaWeappNickname: 修改试用小程序名称
198+
179199
#### 其他小程序相关接口
180200
* Jscode2session: 获取用户openid , session_key
181201
* AESCBCDecrypt: 用于解密用户数据, 例如解密前端获取手机号时获取的加密信息
182202

183-
### 5.代平台方实现业务
184-
* FastRegisterWeapp: 快速创建小程序
185-
* SearchWeapp: 查询创建任务状态
186203

187204
### 小程序模板接口 (全部完成)
188205
* GetTemplateDraftList: 获取代码草稿列表
@@ -199,7 +216,6 @@
199216
* SetWebviewDomain: 设置业务域名
200217

201218

202-
203219
### 小程序类目管理接口 (全部完成)
204220
* GetMiniProgramAllCategory: 获取可以设置的所有类目
205221
* GetMiniProgramCategory: 获取已设置的所有类目

authorizer.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ type AuthorizerInfoResp struct {
7878
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/api_get_authorizer_info.html
7979
func (s *Server) AuthorizerInfo(authorizerAppid string) (resp *AuthorizerInfoResp) {
8080
resp = &AuthorizerInfoResp{}
81-
accessToken, err := s.Token()
81+
token, err := s.Token()
8282
if err != nil {
8383
resp.Err(err)
8484
return
@@ -87,7 +87,7 @@ func (s *Server) AuthorizerInfo(authorizerAppid string) (resp *AuthorizerInfoRes
8787
ComponentAppid: s.cfg.AppID,
8888
AuthorizerAppid: authorizerAppid,
8989
}
90-
resp.Err(core.PostJson(getCompleteUrl(AuthorizerInfoUrl, accessToken), req, resp))
90+
resp.Err(core.PostJson(getCompleteUrl(AuthorizerInfoUrl, token), req, resp))
9191
return
9292
}
9393

@@ -116,7 +116,7 @@ type AuthorizerOptionResp struct {
116116
// 获取选项信息
117117
func (s *Server) AuthorizerOption(authorizerAppid string, optionName AuthorizeOption) (resp *AuthorizerOptionResp) {
118118
resp = &AuthorizerOptionResp{}
119-
accessToken, err := s.Token()
119+
token, err := s.Token()
120120
if err != nil {
121121
resp.Err(err)
122122
return
@@ -126,7 +126,7 @@ func (s *Server) AuthorizerOption(authorizerAppid string, optionName AuthorizeOp
126126
AuthorizerAppid: authorizerAppid,
127127
OptionName: optionName,
128128
}
129-
resp.Err(core.PostJson(getCompleteUrl(AuthorizerOptionUrl, accessToken), req, resp))
129+
resp.Err(core.PostJson(getCompleteUrl(AuthorizerOptionUrl, token), req, resp))
130130
return
131131
}
132132

@@ -142,7 +142,7 @@ type SetAuthorizerOptionResp struct {
142142
// 设置选项信息
143143
func (s *Server) SetAuthorizerOption(authorizerAppid string, optionName AuthorizeOption, optionValue string) (resp *SetAuthorizerOptionResp) {
144144
resp = &SetAuthorizerOptionResp{}
145-
accessToken, err := s.Token()
145+
token, err := s.Token()
146146
if err != nil {
147147
resp.Err(err)
148148
return
@@ -155,7 +155,7 @@ func (s *Server) SetAuthorizerOption(authorizerAppid string, optionName Authoriz
155155
},
156156
OptionValue: optionValue,
157157
}
158-
resp.Err(core.PostJson(getCompleteUrl(SetAuthorizerOptionUrl, accessToken), req, resp))
158+
resp.Err(core.PostJson(getCompleteUrl(SetAuthorizerOptionUrl, token), req, resp))
159159
return
160160
}
161161

@@ -178,7 +178,7 @@ type AuthorizerListResp struct {
178178
// 拉取用户授权列表
179179
func (s *Server) AuthorizerList(offset, count int) (resp *AuthorizerListResp) {
180180
resp = &AuthorizerListResp{}
181-
accessToken, err := s.Token()
181+
token, err := s.Token()
182182
if err != nil {
183183
resp.Err(err)
184184
return
@@ -188,6 +188,6 @@ func (s *Server) AuthorizerList(offset, count int) (resp *AuthorizerListResp) {
188188
Offset: offset,
189189
Count: count,
190190
}
191-
resp.Err(core.PostJson(getCompleteUrl(AuthorizerListUrl, accessToken), req, resp))
191+
resp.Err(core.PostJson(getCompleteUrl(AuthorizerListUrl, token), req, resp))
192192
return
193193
}

bate_weapp.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package wechat3rd
2+
3+
import "github.com/l306287405/wechat3rd/core"
4+
5+
type FastRegisterBetaWeappReq struct {
6+
Name string `json:"name"`
7+
OpenId string `json:"openid"`
8+
}
9+
10+
type FastRegisterBetaWeappResp struct {
11+
core.Error
12+
UniqueId string `json:"unique_id"`
13+
AuthorizeUrl string `json:"authorize_url"`
14+
}
15+
16+
// 创建试用小程序
17+
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/beta_Mini_Programs/fastregister.html
18+
func (s *Server) FastRegisterBetaWeapp(req *FastRegisterBetaWeappReq) (resp *FastRegisterBetaWeappResp) {
19+
var (
20+
u = WECHAT_API_URL + "/wxa/component/fastregisterbetaweapp?"
21+
)
22+
token, err := s.Token()
23+
if err != nil {
24+
resp.Err(err)
25+
return
26+
}
27+
resp = &FastRegisterBetaWeappResp{}
28+
resp.Err(core.PostJson(s.AuthToken2url(u, token), req, resp))
29+
return
30+
}
31+
32+
type VerifyBetaWeappReq struct {
33+
EnterpriseName string `json:"enterprise_name"` //企业名(需与工商部门登记信息一致);如果是“无主体名称个体工商户”则填“个体户+法人姓名”,例如“个体户张三”
34+
Code string `json:"code"` //企业代码
35+
CodeType int8 `json:"code_type"` //企业代码类型 1:统一社会信用代码(18 位) 2:组织机构代码(9 位 xxxxxxxx-x) 3:营业执照注册号(15 位)
36+
LegalPersonaWechat string `json:"legal_persona_wechat"` //法人微信号
37+
LegalPersonaName string `json:"legal_persona_name"` //法人姓名(绑定银行卡)
38+
LegalPersonaIdCard string `json:"legal_persona_idcard"` //法人身份证号
39+
ComponentPhone string `json:"component_phone"` //第三方联系电话
40+
}
41+
42+
// 试用小程序快速认证
43+
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/beta_Mini_Programs/fastverify.html
44+
func (s *Server) VerifyBetaWeapp(accessToken string, req *VerifyBetaWeappReq) (resp *core.Error) {
45+
var (
46+
u = WECHAT_API_URL + "/wxa/verifybetaweapp?"
47+
r = struct {
48+
VerifyInfo *VerifyBetaWeappReq `json:"verify_info"`
49+
}{VerifyInfo: req}
50+
)
51+
resp = &core.Error{}
52+
resp.Err(core.PostJson(s.AuthToken2url(u, accessToken), r, resp))
53+
return
54+
}
55+
56+
// 修改试用小程序名称
57+
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/beta_Mini_Programs/fastmodify.html
58+
func (s *Server) SetBetaWeappNickname(accessToken string, name string) (resp *core.Error) {
59+
var (
60+
u = WECHAT_API_URL + "/wxa/setbetaweappnickname?"
61+
r = struct {
62+
Name string `json:"name"`
63+
}{Name: name}
64+
)
65+
resp = &core.Error{}
66+
resp.Err(core.PostJson(s.AuthToken2url(u, accessToken), r, resp))
67+
return
68+
}

fastregisterweapp.go

Lines changed: 128 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import (
55
"net/url"
66
)
77

8-
const WeAPPRegisterUrl = "https://api.weixin.qq.com/cgi-bin/component/fastregisterweapp?"
8+
const OrgWeAPPRegisterUrl = "https://api.weixin.qq.com/cgi-bin/component/fastregisterweapp?"
9+
const PersonalWeAPPRegisterUrl = "https://api.weixin.qq.com/wxa/component/fastregisterpersonalweapp?"
910

1011
type FastRegisterWeappReq struct {
1112
Name string `json:"name"` //企业名
@@ -16,8 +17,9 @@ type FastRegisterWeappReq struct {
1617
ComponentPhone string `json:"component_phone"` //第三方联系电话
1718
}
1819

19-
//快速注册小程序
20+
// FastRegisterWeapp 快速注册小程序
2021
//https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Register_Mini_Programs/Fast_Registration_Interface_document.html
22+
//Deprecated: 转用 FastRegisterOrgWeapp 方法
2123
func (s *Server) FastRegisterWeapp(req *FastRegisterWeappReq) (resp *core.Error) {
2224
var (
2325
p = make(url.Values)
@@ -33,7 +35,37 @@ func (s *Server) FastRegisterWeapp(req *FastRegisterWeappReq) (resp *core.Error)
3335
}
3436
p.Set("action", "create")
3537
p.Set("component_access_token", token)
36-
resp.Err(core.PostJson(WeAPPRegisterUrl+p.Encode(), req, resp))
38+
resp.Err(core.PostJson(OrgWeAPPRegisterUrl+p.Encode(), req, resp))
39+
return
40+
}
41+
42+
type FastRegisterOrgWeappReq struct {
43+
Name string `json:"name"` //企业名
44+
Code string `json:"code"` //企业代码
45+
CodeType int8 `json:"code_type"` //企业代码类型(1:统一社会信用代码, 2:组织机构代码,3:营业执照注册号)
46+
LegalPersonaWechat string `json:"legal_persona_wechat"` //法人微信
47+
LegalPersonaName string `json:"legal_persona_name"` //法人姓名(绑定银行卡)
48+
ComponentPhone string `json:"component_phone"` //第三方联系电话
49+
}
50+
51+
// FastRegisterOrgWeapp 快速注册小程序
52+
//https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Register_Mini_Programs/Fast_Registration_Interface_document.html
53+
func (s *Server) FastRegisterOrgWeapp(req *FastRegisterWeappReq) (resp *core.Error) {
54+
var (
55+
p = make(url.Values)
56+
token string
57+
err error
58+
)
59+
resp = &core.Error{}
60+
61+
token, err = s.Token()
62+
if err != nil {
63+
resp.Err(err)
64+
return
65+
}
66+
p.Set("action", "create")
67+
p.Set("component_access_token", token)
68+
resp.Err(core.PostJson(OrgWeAPPRegisterUrl+p.Encode(), req, resp))
3769
return
3870
}
3971

@@ -43,8 +75,9 @@ type SearchWeappReq struct {
4375
LegalPersonaName string `json:"legal_persona_name"` //法人姓名(绑定银行卡)
4476
}
4577

46-
//查询创建任务状态
78+
// SearchWeapp 查询创建任务状态
4779
//https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Register_Mini_Programs/Fast_Registration_Interface_document.html
80+
//Deprecated: 转用 QueryOrgWeapp 方法
4881
func (s *Server) SearchWeapp(req *SearchWeappReq) (resp *core.Error) {
4982
var (
5083
p = make(url.Values)
@@ -59,6 +92,96 @@ func (s *Server) SearchWeapp(req *SearchWeappReq) (resp *core.Error) {
5992
}
6093
p.Set("action", "search")
6194
p.Set("component_access_token", token)
62-
resp.Err(core.PostJson(WeAPPRegisterUrl+p.Encode(), req, resp))
95+
resp.Err(core.PostJson(OrgWeAPPRegisterUrl+p.Encode(), req, resp))
96+
return
97+
}
98+
99+
type QueryOrgWeappReq struct {
100+
Name string `json:"name"` //企业名
101+
LegalPersonaWechat string `json:"legal_persona_wechat"` //法人微信
102+
LegalPersonaName string `json:"legal_persona_name"` //法人姓名(绑定银行卡)
103+
}
104+
105+
// QueryOrgWeapp 查询创建任务状态
106+
//https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Register_Mini_Programs/Fast_Registration_Interface_document.html
107+
func (s *Server) QueryOrgWeapp(req *SearchWeappReq) (resp *core.Error) {
108+
var (
109+
p = make(url.Values)
110+
token string
111+
err error
112+
)
113+
resp = &core.Error{}
114+
token, err = s.Token()
115+
if err != nil {
116+
resp.Err(err)
117+
return
118+
}
119+
p.Set("action", "search")
120+
p.Set("component_access_token", token)
121+
resp.Err(core.PostJson(OrgWeAPPRegisterUrl+p.Encode(), req, resp))
122+
return
123+
}
124+
125+
type FastRegisterPersonalWeappReq struct {
126+
IdName string `json:"idname"` //个人用户名称
127+
WxUser string `json:"wxuser"` //个人用户微信号
128+
ComponentPhone *string `json:"component_phone,omitempty"` //第三方联系电话
129+
}
130+
131+
type FastRegisterPersonalWeappResp struct {
132+
core.Error
133+
taskid string // 任务id,后面query查询需要用到
134+
authorize_url string // 给用户扫码认证的验证url
135+
status int // 任务的状态
136+
}
137+
138+
// FastRegisterPersonalWeapp 快速注册个人小程序
139+
//https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Register_Mini_Programs/fastregisterpersonalweapp.html
140+
func (s *Server) FastRegisterPersonalWeapp(req *FastRegisterPersonalWeappReq) (resp *FastRegisterPersonalWeappResp) {
141+
var (
142+
p = make(url.Values)
143+
token string
144+
err error
145+
)
146+
resp = &FastRegisterPersonalWeappResp{}
147+
148+
token, err = s.Token()
149+
if err != nil {
150+
resp.Err(err)
151+
return
152+
}
153+
p.Set("action", "create")
154+
p.Set("component_access_token", token)
155+
resp.Err(core.PostJson(PersonalWeAPPRegisterUrl+p.Encode(), req, resp))
156+
return
157+
}
158+
159+
type QueryPersonalWeappResp struct {
160+
core.Error
161+
TaskId string `json:"taskid"`
162+
AuthorizeUrl string `json:"authorize_url"`
163+
Status int `json:"status"`
164+
}
165+
166+
//查询个人小程序创建任务状态接口详情
167+
//https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Register_Mini_Programs/fastregisterpersonalweapp.html
168+
func (s *Server) QueryPersonalWeapp(taskId string) (resp *QueryPersonalWeappResp) {
169+
var (
170+
p = make(url.Values)
171+
token string
172+
err error
173+
req = &struct {
174+
TaskId string `json:"taskid"`
175+
}{TaskId: taskId}
176+
)
177+
resp = &QueryPersonalWeappResp{}
178+
token, err = s.Token()
179+
if err != nil {
180+
resp.Err(err)
181+
return
182+
}
183+
p.Set("action", "query")
184+
p.Set("component_access_token", token)
185+
resp.Err(core.PostJson(PersonalWeAPPRegisterUrl+p.Encode(), req, resp))
63186
return
64187
}

0 commit comments

Comments
 (0)