mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 12:52:27 +08:00
微信开放平台-代处理小程序
This commit is contained in:
52
openplatform/miniprogram/basic/basic.go
Normal file
52
openplatform/miniprogram/basic/basic.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package basic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
openContext "github.com/silenceper/wechat/v2/openplatform/context"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
getAccountBasicInfoURL = "https://api.weixin.qq.com/cgi-bin/account/getaccountbasicinfo"
|
||||
)
|
||||
|
||||
//Basic 基础信息设置
|
||||
type Basic struct {
|
||||
*openContext.Context
|
||||
appID string
|
||||
}
|
||||
|
||||
//NewBasic new
|
||||
func NewBasic(opContext *openContext.Context, appID string) *Basic {
|
||||
return &Basic{Context: opContext, appID: appID}
|
||||
}
|
||||
|
||||
//AccountBasicInfo 基础信息
|
||||
type AccountBasicInfo struct {
|
||||
util.CommonError
|
||||
}
|
||||
|
||||
//GetAccountBasicInfo 获取小程序基础信息
|
||||
//reference:https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Mini_Programs/Mini_Program_Information_Settings.html
|
||||
func (basic *Basic) GetAccountBasicInfo() (*AccountBasicInfo, error) {
|
||||
ak, err := basic.GetAuthrAccessToken(basic.AppID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
url := fmt.Sprintf("%s?access_token=%s", getAccountBasicInfoURL, ak)
|
||||
data, err := util.HTTPGet(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &AccountBasicInfo{}
|
||||
if err := util.DecodeWithError(data, result, "account/getaccountbasicinfo"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
//modify_domain设置服务器域名
|
||||
//TODO
|
||||
//func (basic *Basic) modifyDomain() {
|
||||
//}
|
||||
69
openplatform/miniprogram/component/component.go
Normal file
69
openplatform/miniprogram/component/component.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package component
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
openContext "github.com/silenceper/wechat/v2/openplatform/context"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
fastregisterweappURL = "https://api.weixin.qq.com/cgi-bin/component/fastregisterweapp"
|
||||
)
|
||||
|
||||
//Component 快速创建小程序
|
||||
type Component struct {
|
||||
*openContext.Context
|
||||
}
|
||||
|
||||
//NewComponent new
|
||||
func NewComponent(opContext *openContext.Context) *Component {
|
||||
return &Component{opContext}
|
||||
}
|
||||
|
||||
//RegisterMiniProgramParam 快速注册小程序参数
|
||||
type RegisterMiniProgramParam struct {
|
||||
Name string `json:"name"` //企业名
|
||||
Code string `json:"code"` //企业代码
|
||||
CodeType string `json:"code_type"` //企业代码类型 1:统一社会信用代码(18 位) 2:组织机构代码(9 位 xxxxxxxx-x) 3:营业执照注册号(15 位)
|
||||
LegalPersonaWechat string `json:"legal_persona_wechat"` //法人微信号
|
||||
LegalPersonaName string `json:"legal_persona_name"` //法人姓名(绑定银行卡)
|
||||
ComponentPhone string `json:"component_phone"` //第三方联系电话(方便法人与第三方联系)
|
||||
}
|
||||
|
||||
//RegisterMiniProgram 快速创建小程
|
||||
//reference: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Mini_Programs/Fast_Registration_Interface_document.html
|
||||
func (component *Component) RegisterMiniProgram(param *RegisterMiniProgramParam) error {
|
||||
componentAK, err := component.GetComponentAccessToken()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
url := fmt.Sprintf(fastregisterweappURL+"?action=create&component_access_token=%s", componentAK)
|
||||
data, err := util.PostJSON(url, param)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return util.DecodeWithCommonError(data, "component/fastregisterweapp?action=create")
|
||||
}
|
||||
|
||||
//GetRegistrationStatusParam 查询任务创建状态
|
||||
type GetRegistrationStatusParam struct {
|
||||
Name string `json:"name"` //企业名
|
||||
LegalPersonaWechat string `json:"legal_persona_wechat"` //法人微信号
|
||||
LegalPersonaName string `json:"legal_persona_name"` //法人姓名(绑定银行卡)
|
||||
|
||||
}
|
||||
|
||||
//GetRegistrationStatus 查询创建任务状态.
|
||||
func (component *Component) GetRegistrationStatus(param *GetRegistrationStatusParam) error {
|
||||
componentAK, err := component.GetComponentAccessToken()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
url := fmt.Sprintf(fastregisterweappURL+"?action=search&component_access_token=%s", componentAK)
|
||||
data, err := util.PostJSON(url, param)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return util.DecodeWithCommonError(data, "component/fastregisterweapp?action=search")
|
||||
}
|
||||
32
openplatform/miniprogram/miniprogram.go
Normal file
32
openplatform/miniprogram/miniprogram.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package miniprogram
|
||||
|
||||
import (
|
||||
openContext "github.com/silenceper/wechat/v2/openplatform/context"
|
||||
"github.com/silenceper/wechat/v2/openplatform/miniprogram/basic"
|
||||
"github.com/silenceper/wechat/v2/openplatform/miniprogram/component"
|
||||
)
|
||||
|
||||
//MiniProgram 代小程序实现业务
|
||||
type MiniProgram struct {
|
||||
AppID string
|
||||
openContext *openContext.Context
|
||||
}
|
||||
|
||||
//NewMiniProgram 实例化
|
||||
func NewMiniProgram(opCtx *openContext.Context, appID string) *MiniProgram {
|
||||
return &MiniProgram{
|
||||
openContext: opCtx,
|
||||
AppID: appID,
|
||||
}
|
||||
}
|
||||
|
||||
//GetComponent get component
|
||||
//快速注册小程序相关
|
||||
func (miniProgram *MiniProgram) GetComponent() *component.Component {
|
||||
return component.NewComponent(miniProgram.openContext)
|
||||
}
|
||||
|
||||
//GetBasic 基础信息设置
|
||||
func (miniProgram *MiniProgram) GetBasic() *basic.Basic {
|
||||
return basic.NewBasic(miniProgram.openContext, miniProgram.AppID)
|
||||
}
|
||||
Reference in New Issue
Block a user