mirror of
https://github.com/silenceper/wechat.git
synced 2026-11-16 05:12:03 +08:00
feat(miniprogram): 添加学生身份核验和通用API调用功能 (#893)
* feat: 添加 微信物流服务 /微信物流服务(商家查看) /消息组件 * fix lint issues * fix: 查询运单详情信息返回结果结构 * 追加官方文档地址 * feat: 追加接口【微信物流服务 /微信物流服务(商家查看) /查询组件】 * fix: comments * fix: indents * feat(miniprogram): 添加学生身份核验和通用API调用功能 - 新增学生身份核验模块,支持快速获取学生身份接口 - 添加通用API调用功能,用于访问SDK尚未封装的小程序接口 - 实现GET/POST请求及响应解码的通用方法 - 在文档中补充学生身份相关API说明
This commit is contained in:
1 parent
2bc22dc4ae
commit
ad48392a5b
4 files changed
+221
No files matched your search
@@ -0,0 +1,73 @@
|
||||
package student
|
||||
|
||||
import (
|
||||
context2 "context"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/miniprogram/context"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
// quickCheckStudentIdentityURL 快速获取学生身份
|
||||
quickCheckStudentIdentityURL = "https://api.weixin.qq.com/intp/quickcheckstudentidentity?access_token=%s"
|
||||
)
|
||||
|
||||
// Student 学生身份核验
|
||||
type Student struct {
|
||||
*context.Context
|
||||
}
|
||||
|
||||
// NewStudent init
|
||||
func NewStudent(ctx *context.Context) *Student {
|
||||
return &Student{ctx}
|
||||
}
|
||||
|
||||
// BindStatus 学生身份绑定状态
|
||||
type BindStatus int
|
||||
|
||||
const (
|
||||
// BindStatusUnbound 未绑定
|
||||
BindStatusUnbound BindStatus = 1
|
||||
// BindStatusAuditing 审核中
|
||||
BindStatusAuditing BindStatus = 2
|
||||
// BindStatusBound 已绑定
|
||||
BindStatusBound BindStatus = 3
|
||||
)
|
||||
|
||||
// QuickCheckStudentIdentityRequest 快速获取学生身份请求参数
|
||||
type QuickCheckStudentIdentityRequest struct {
|
||||
OpenID string `json:"openid"` // 用户在业务方下的openid,需为已开通接口权限小程序对应的用户openid
|
||||
WxStudentCheckCode string `json:"wx_studentcheck_code"` // 用户授权查询code,由授权插件返回,code有效期两小时
|
||||
}
|
||||
|
||||
// QuickCheckStudentIdentityResponse 快速获取学生身份返回参数
|
||||
type QuickCheckStudentIdentityResponse struct {
|
||||
util.CommonError
|
||||
BindStatus BindStatus `json:"bind_status"` // 绑定状态:1-未绑定,2-审核中,3-已绑定
|
||||
IsStudent bool `json:"is_student"` // 用户学生身份绑定状态说明,true-是学生,false-不是学生
|
||||
}
|
||||
|
||||
// QuickCheckStudentIdentity 快速获取学生身份
|
||||
// see https://developers.weixin.qq.com/miniprogram/dev/server/API/student/api_quickcheckstudentidentity.html
|
||||
func (student *Student) QuickCheckStudentIdentity(in *QuickCheckStudentIdentityRequest) (out QuickCheckStudentIdentityResponse, err error) {
|
||||
return student.QuickCheckStudentIdentityContext(context2.Background(), in)
|
||||
}
|
||||
|
||||
// QuickCheckStudentIdentityContext 快速获取学生身份
|
||||
func (student *Student) QuickCheckStudentIdentityContext(ctx context2.Context, in *QuickCheckStudentIdentityRequest) (out QuickCheckStudentIdentityResponse, err error) {
|
||||
var accessToken string
|
||||
if accessToken, err = student.GetAccessTokenContext(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
uri := fmt.Sprintf(quickCheckStudentIdentityURL, accessToken)
|
||||
var response []byte
|
||||
if response, err = util.PostJSONContext(ctx, uri, in); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, &out, "student.QuickCheckStudentIdentity")
|
||||
return
|
||||
}
|
||||
Reference in new issue
Block a user