Skip to content

Commit

Permalink
feat(payment): add Apply4Sub client
Browse files Browse the repository at this point in the history
  • Loading branch information
Matrix-X committed Jun 11, 2023
1 parent 60219db commit 0b6d99f
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/payment/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/models"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/providers"
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/apply4Sub"
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/base"
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/bill"
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/jssdk"
Expand Down Expand Up @@ -47,6 +48,8 @@ type Payment struct {
Reverse *reverse.Client
ProfitSharing *profitSharing.Client

Apply4Sub *apply4Sub.Client

Base *base.Client

Security *security.Client
Expand Down Expand Up @@ -191,6 +194,12 @@ func NewPayment(config *UserConfig) (*Payment, error) {
return nil, err
}

//-------------- Apply4Sub --------------
app.Apply4Sub, err = apply4Sub.RegisterProvider(app)
if err != nil {
return nil, err
}

//-------------- Security --------------
app.Security, err = security.RegisterProvider(app)
if err != nil {
Expand Down Expand Up @@ -240,6 +249,8 @@ func (app *Payment) GetComponent(name string) interface{} {
return app.Reverse
case "ProfitSharing":
return app.ProfitSharing
case "Apply4Sub":
return app.Apply4Sub

case "Security":
return app.Security
Expand Down
65 changes: 65 additions & 0 deletions src/payment/apply4Sub/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package apply4Sub

import (
"context"
"crypto"
"encoding/base64"
"github.com/ArtisanCloud/PowerLibs/v3/object"
"github.com/ArtisanCloud/PowerLibs/v3/security/sign"
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/apply4Sub/request"
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/apply4Sub/response"
payment "github.com/ArtisanCloud/PowerWeChat/v3/src/payment/kernel"
"net/http"
)

type Client struct {
*payment.BaseClient
}

func NewClient(app *payment.ApplicationPaymentInterface) (*Client, error) {
baseClient, err := payment.NewBaseClient(app)
if err != nil {
return nil, err
}
return &Client{
baseClient,
}, nil
}

// 特约商户进件
// https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter11_1_1.shtml
func (comp *Client) ApplyForBusiness(ctx context.Context, params *request.RequestApply) (*response.ResponseApply, error) {

result := &response.ResponseApply{}

config := (*comp.App).GetConfig()

rsaSigner, err := sign.NewRSASigner(crypto.SHA1)
if err != nil {
return nil, err
}
rsaSigner.RSAEncryptor.PublicKeyPath = config.GetString("rsa_public_key_path", "")
_, err = rsaSigner.RSAEncryptor.LoadPublicKeyByPath()
if err != nil {
return nil, err
}

cipherData, err := rsaSigner.RSAEncryptor.Encrypt([]byte(params.ContactInfo.ContactEmail))
buffer := base64.StdEncoding.EncodeToString(cipherData)
if err != nil {
return nil, err
}
params.ContactInfo.ContactEmail = string(buffer)
if err != nil {
return nil, err
}

options, err := object.StructToHashMap(params)
if err != nil {
return nil, err
}

endpoint := "/v3/applyment4sub/applyment/"
_, err = comp.Request(ctx, comp.Wrap(endpoint), nil, http.MethodPost, options, false, nil, result)
return result, err
}
11 changes: 11 additions & 0 deletions src/payment/apply4Sub/provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package apply4Sub

import (
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/kernel"
)

func RegisterProvider(app kernel.ApplicationPaymentInterface) (*Client, error) {

return NewClient(&app)

}
115 changes: 115 additions & 0 deletions src/payment/apply4Sub/request/requestApplyment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package request

type RequestApply struct {
BusinessCode string `json:"business_code"`
ContactInfo struct {
BusinessAuthorizationLetter string `json:"business_authorization_letter"`
ContactEmail string `json:"contact_email"`
ContactIdDocCopy string `json:"contact_id_doc_copy"`
ContactIdDocCopyBack string `json:"contact_id_doc_copy_back"`
ContactIdDocType string `json:"contact_id_doc_type"`
ContactIdNumber string `json:"contact_id_number"`
ContactName string `json:"contact_name"`
ContactPeriodBegin string `json:"contact_period_begin"`
ContactPeriodEnd string `json:"contact_period_end"`
ContactType string `json:"contact_type"`
MobilePhone string `json:"mobile_phone"`
Openid int `json:"openid"`
} `json:"contact_info"`
SubjectInfo struct {
SubjectType string `json:"subject_type"`
FinanceInstitution bool `json:"finance_institution"`
BusinessLicenseInfo struct {
LegalPerson string `json:"legal_person"`
LicenseAddress string `json:"license_address"`
LicenseCopy string `json:"license_copy"`
LicenseNumber string `json:"license_number"`
MerchantName string `json:"merchant_name"`
PeriodBegin string `json:"period_begin"`
PeriodEnd string `json:"period_end"`
} `json:"business_license_info"`
CertificateLetterCopy string `json:"certificate_letter_copy"`
FinanceInstitutionInfo struct {
FinanceLicensePics []string `json:"finance_license_pics"`
FinanceType string `json:"finance_type"`
} `json:"finance_institution_info"`
IdentityInfo struct {
AuthorizeLetterCopy string `json:"authorize_letter_copy"`
IdCardInfo struct {
CardPeriodBegin string `json:"card_period_begin"`
CardPeriodEnd string `json:"card_period_end"`
IdCardAddress string `json:"id_card_address"`
IdCardCopy string `json:"id_card_copy"`
IdCardName string `json:"id_card_name"`
IdCardNational string `json:"id_card_national"`
IdCardNumber string `json:"id_card_number"`
} `json:"id_card_info"`
IdDocType string `json:"id_doc_type"`
IdHolderType string `json:"id_holder_type"`
Owner bool `json:"owner"`
} `json:"identity_info"`
UboInfoList []struct {
UboIdDocAddress string `json:"ubo_id_doc_address"`
UboIdDocCopy string `json:"ubo_id_doc_copy"`
UboIdDocCopyBack string `json:"ubo_id_doc_copy_back"`
UboIdDocName string `json:"ubo_id_doc_name"`
UboIdDocNumber string `json:"ubo_id_doc_number"`
UboIdDocType string `json:"ubo_id_doc_type"`
UboPeriodBegin string `json:"ubo_period_begin"`
UboPeriodEnd string `json:"ubo_period_end"`
} `json:"ubo_info_list"`
} `json:"subject_info"`
BusinessInfo struct {
MerchantShortname string `json:"merchant_shortname"`
SalesInfo struct {
AppInfo struct {
AppAppid string `json:"app_appid"`
AppPics []string `json:"app_pics"`
} `json:"app_info"`
BizStoreInfo struct {
BizAddressCode string `json:"biz_address_code"`
BizStoreAddress string `json:"biz_store_address"`
BizStoreName string `json:"biz_store_name"`
BizSubAppid string `json:"biz_sub_appid"`
IndoorPic []string `json:"indoor_pic"`
StoreEntrancePic []string `json:"store_entrance_pic"`
} `json:"biz_store_info"`
MiniProgramInfo struct {
MiniProgramAppid string `json:"mini_program_appid"`
MiniProgramPics []string `json:"mini_program_pics"`
} `json:"mini_program_info"`
MpInfo struct {
MpAppid string `json:"mp_appid"`
MpPics []string `json:"mp_pics"`
} `json:"mp_info"`
SalesScenesType []string `json:"sales_scenes_type"`
WebInfo struct {
Domain string `json:"domain"`
WebAppid string `json:"web_appid"`
WebAuthorisation string `json:"web_authorisation"`
} `json:"web_info"`
WeworkInfo struct {
CorpId string `json:"corp_id"`
SubCorpId string `json:"sub_corp_id"`
WeworkPics []string `json:"wework_pics"`
} `json:"wework_info"`
} `json:"sales_info"`
ServicePhone string `json:"service_phone"`
} `json:"business_info"`
SettlementInfo struct {
ActivitiesAdditions []string `json:"activities_additions"`
ActivitiesId string `json:"activities_id"`
ActivitiesRate string `json:"activities_rate"`
QualificationType string `json:"qualification_type"`
Qualifications string `json:"qualifications"`
SettlementId string `json:"settlement_id"`
} `json:"settlement_info"`
BankAccountInfo struct {
AccountBank string `json:"account_bank"`
AccountName string `json:"account_name"`
AccountNumber string `json:"account_number"`
BankAccountType string `json:"bank_account_type"`
BankAddressCode string `json:"bank_address_code"`
BankBranchId string `json:"bank_branch_id"`
} `json:"bank_account_info"`
}
5 changes: 5 additions & 0 deletions src/payment/apply4Sub/response/responseApply.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package response

type ResponseApply struct {
ApplymentId int64 `json:"applyment_id"`
}

0 comments on commit 0b6d99f

Please sign in to comment.