silenceper 6 лет назад
Родитель
Сommit
51cbfab087

+ 1 - 0
officialaccount/message/message.go

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

+ 52 - 0
openplatform/miniprogram/basic/basic.go

@@ -0,0 +1,52 @@
+package basic
+
+import (
+	"fmt"
+
+	opContext "github.com/silenceper/wechat/openplatform/context"
+	"github.com/silenceper/wechat/util"
+)
+
+const (
+	getAccountBasicInfoURL = "https://api.weixin.qq.com/cgi-bin/account/getaccountbasicinfo"
+)
+
+//Basic 基础信息设置
+type Basic struct {
+	*opContext.Context
+	appID string
+}
+
+//NewBasic new
+func NewBasic(opContext *opContext.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 - 0
openplatform/miniprogram/component/component.go

@@ -0,0 +1,69 @@
+package component
+
+import (
+	"fmt"
+
+	opContext "github.com/silenceper/wechat/openplatform/context"
+	"github.com/silenceper/wechat/util"
+)
+
+const (
+	fastregisterweappURL = "https://api.weixin.qq.com/cgi-bin/component/fastregisterweapp"
+)
+
+//Component 快速创建小程序
+type Component struct {
+	*opContext.Context
+}
+
+//NewComponent new
+func NewComponent(opContext *opContext.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 - 0
openplatform/miniprogram/miniprogram.go

@@ -0,0 +1,32 @@
+package miniprogram
+
+import (
+	opContext "github.com/silenceper/wechat/openplatform/context"
+	"github.com/silenceper/wechat/openplatform/miniprogram/basic"
+	"github.com/silenceper/wechat/openplatform/miniprogram/component"
+)
+
+//MiniProgram 代小程序实现业务
+type MiniProgram struct {
+	AppID     string
+	opContext *opContext.Context
+}
+
+//NewMiniProgram 实例化
+func NewMiniProgram(opCtx *opContext.Context, appID string) *MiniProgram {
+	return &MiniProgram{
+		opContext: opCtx,
+		AppID:     appID,
+	}
+}
+
+//GetComponent get component
+//快速注册小程序相关
+func (miniProgram *MiniProgram) GetComponent() *component.Component {
+	return component.NewComponent(miniProgram.opContext)
+}
+
+//GetBasic 基础信息设置
+func (miniProgram *MiniProgram) GetBasic() *basic.Basic {
+	return basic.NewBasic(miniProgram.opContext)
+}

+ 1 - 0
openplatform/officialaccount/officialaccount.go

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

+ 6 - 0
openplatform/openplatform.go

@@ -3,6 +3,7 @@ package openplatform
 import (
 	"github.com/silenceper/wechat/openplatform/config"
 	"github.com/silenceper/wechat/openplatform/context"
+	"github.com/silenceper/wechat/openplatform/miniprogram"
 	"github.com/silenceper/wechat/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)
+}