1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-04 12:52:27 +08:00

微信开放平台-代处理小程序

This commit is contained in:
silenceper
2020-05-23 12:02:55 +08:00
parent 85b0a114dc
commit c372d7a83c
6 changed files with 161 additions and 0 deletions

View File

@@ -73,6 +73,7 @@ const (
const (
//微信开放平台需要用到
// InfoTypeVerifyTicket 返回ticket
InfoTypeVerifyTicket InfoType = "component_verify_ticket"
// InfoTypeAuthorized 授权

View 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() {
//}

View 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")
}

View 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)
}

View File

@@ -7,6 +7,7 @@ import (
opContext "github.com/silenceper/wechat/v2/openplatform/context"
)
//OfficialAccount 代公众号实现业务
type OfficialAccount struct {
//授权的公众号的appID
appID string

View File

@@ -3,6 +3,7 @@ package openplatform
import (
"github.com/silenceper/wechat/v2/openplatform/config"
"github.com/silenceper/wechat/v2/openplatform/context"
"github.com/silenceper/wechat/v2/openplatform/miniprogram"
"github.com/silenceper/wechat/v2/openplatform/officialaccount"
)
@@ -26,3 +27,8 @@ func NewOpenPlatform(cfg *config.Config) *OpenPlatform {
func (openPlatform *OpenPlatform) GetOfficialAccount(appID string) *officialaccount.OfficialAccount {
return officialaccount.NewOfficialAccount(openPlatform.Context, appID)
}
//GetMiniProgram 小程序代理
func (openPlatform *OpenPlatform) GetMiniProgram(opCtx *context.Context, appID string) *miniprogram.MiniProgram {
return miniprogram.NewMiniProgram(opCtx, appID)
}