Skip to content

Commit

Permalink
Merge pull request #3 from alipay/feature-update-p1
Browse files Browse the repository at this point in the history
update-p1
  • Loading branch information
ScottWryyyyy authored Oct 9, 2024
2 parents af40706 + d23b3ec commit a458796
Show file tree
Hide file tree
Showing 62 changed files with 1,393 additions and 23 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Changelog


## 1.2.1 - 2024-09-30
* [#3](https://github.com/alipay/global-open-sdk-go/pull/3) update-p1
* add MARKETPLACE - demo
* add vaulting - demo
* add Dispute - demo
* add risk
* add Notify


## 1.2.0 - 2024-09-27
* [#2](https://github.com/alipay/global-open-sdk-go/pull/2) go-sdk-update-release
* go-sdk-update-release
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
```
Language:GO
GO version:1.22.5+
Tags:v1.2.0
Tags:v1.2.1
Copyright:Ant financial services group
```

Expand Down
31 changes: 22 additions & 9 deletions com/alipay/api/defaultAlipayClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ import (
"github.com/alipay/global-open-sdk-go/com/alipay/api/request"
"io/ioutil"
"log"
"net"
"net/http"
"net/url"
"strconv"
"strings"
"time"
)

const readTimeout = 15 * time.Second
const connectTimeout = 15 * time.Second
const totalTimeout = 30 * time.Second

type DefaultAlipayClient struct {
GatewayUrl string
ClientId string
Expand Down Expand Up @@ -61,14 +66,22 @@ func NewDefaultAlipayClient(gatewayUrl string, clientId string, merchantPrivateK
// @Return 返回类型 "错误信息"
func (alipayClient *DefaultAlipayClient) httpDo(url, method string, params, headers map[string]string, data []byte, alipayResponse any) (any, error) {

//自定义cient
trans := &http.Transport{
DialContext: (&net.Dialer{
Timeout: connectTimeout,
}).DialContext,
ResponseHeaderTimeout: readTimeout,
}

//自定义client
client := &http.Client{
Timeout: 5 * time.Second, // 超时时间:5秒
Timeout: totalTimeout,
Transport: trans,
}
//http.post等方法只是在NewRequest上又封装来了一层而已
req, err := http.NewRequest(method, url, bytes.NewBuffer(data))
if err != nil {
return nil, &exception.AlipaySDKError{Message: "http.NewRequest is fail " + err.Error()}
return nil, &exception.AlipayLibraryError{Message: "http.NewRequest is fail " + err.Error()}
}
req.Header.Set("Content-type", "application/json")

Expand All @@ -87,7 +100,7 @@ func (alipayClient *DefaultAlipayClient) httpDo(url, method string, params, head
}
resp, err := client.Do(req)
if err != nil {
return nil, &exception.AlipaySDKError{Message: "client.Do is fail " + err.Error()}
return nil, &exception.AlipayLibraryError{Message: "client.Do is fail " + err.Error()}
}
defer resp.Body.Close()

Expand All @@ -96,7 +109,7 @@ func (alipayClient *DefaultAlipayClient) httpDo(url, method string, params, head
//但是我们在上次必然已经定义了any的类型
err = json.Unmarshal(body, alipayResponse)
if err != nil {
return nil, &exception.AlipaySDKError{Message: "json.Unmarshal is fail " + err.Error()}
return nil, &exception.AlipayLibraryError{Message: "json.Unmarshal is fail " + err.Error()}
}

return alipayResponse, nil
Expand All @@ -105,7 +118,7 @@ func (alipayClient *DefaultAlipayClient) httpDo(url, method string, params, head
func (alipayClient *DefaultAlipayClient) Execute(alipayRequest *request.AlipayRequest) (any, error) {
reqPayload, err := json.Marshal(alipayRequest.Param)
if err != nil {
return nil, &exception.AlipaySDKError{Message: "json.Marshal is fail " + err.Error()}
return nil, &exception.AlipayLibraryError{Message: "json.Marshal is fail " + err.Error()}
}
path := alipayRequest.Path
httpMethod := alipayRequest.HttpMethod
Expand All @@ -128,16 +141,16 @@ func getPkcsKeu(key string) string {
func genSign(httpMethod string, path string, clientId string, reqTime string, reqBody string, merchantPrivateKey string) (string, error) {
block, _ := pem.Decode([]byte(merchantPrivateKey))
if block == nil {
return "", &exception.AlipaySDKError{Message: "Failed to decode private key"}
return "", &exception.AlipayLibraryError{Message: "Failed to decode private key"}
}
privateKey, err := x509.ParsePKCS8PrivateKey(block.Bytes)
if err != nil {
return "", &exception.AlipaySDKError{Message: "Failed to parse private key " + err.Error()}
return "", &exception.AlipayLibraryError{Message: "Failed to parse private key " + err.Error()}
}
payload := genSignContent(httpMethod, path, clientId, reqTime, reqBody)
signature, err := Sign(privateKey.(*rsa.PrivateKey), []byte(payload))
if err != nil {
return "", &exception.AlipaySDKError{Message: "Failed to sign data " + err.Error()}
return "", &exception.AlipayLibraryError{Message: "Failed to sign data " + err.Error()}
}

return signature, nil
Expand Down
4 changes: 2 additions & 2 deletions com/alipay/api/exception/exception.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package exception

import "fmt"

type AlipaySDKError struct {
type AlipayLibraryError struct {
Message string
}

func (p *AlipaySDKError) Error() string {
func (p *AlipayLibraryError) Error() string {
return fmt.Sprintf("AlipaySDKErrore=%s", p.Message)
}
9 changes: 9 additions & 0 deletions com/alipay/api/model/AccountBalance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package model

type AccountBalance struct {
AccountNo string `json:"accountNo,omitempty"`
Currency string `json:"currency,omitempty"`
AvailableBalance *Amount `json:"availableBalance,omitempty"`
FrozenBalance *Amount `json:"frozenBalance,omitempty"`
TotalBalance *Amount `json:"totalBalance,omitempty"`
}
23 changes: 23 additions & 0 deletions com/alipay/api/model/AttachmentType.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package model

type AttachmentType string

const (
AttachmentType_SIGNATURE_AUTHORIZATION_LETTER AttachmentType = "SIGNATURE_AUTHORIZATION_LETTER"
AttachmentType_ARTICLES_OF_ASSOCIATION AttachmentType = "ARTICLES_OF_ASSOCIATION"
AttachmentType_LOGO AttachmentType = "LOGO"

AttachmentType_AUTHORIZER_SIGNATURE_CONFIRMATION_LETTER AttachmentType = "AUTHORIZER_SIGNATURE_CONFIRMATION_LETTER"
AttachmentType_ASSOCIATION_ARTICLE AttachmentType = "ASSOCIATION_ARTICLE"
AttachmentType_FINANCIAL_REPORT AttachmentType = "FINANCIAL_REPORT"
AttachmentType_OWNERSHIP_STRUCTURE_PIC AttachmentType = "OWNERSHIP_STRUCTURE_PIC"
AttachmentType_ADDRESS_PROOF AttachmentType = "ADDRESS_PROOF"
AttachmentType_UBO_PROVE AttachmentType = "UBO_PROVE"
AttachmentType_ENTERPRISE_REGISTRATION AttachmentType = "ENTERPRISE_REGISTRATION"
AttachmentType_LICENSE_INFO AttachmentType = "LICENSE_INFO"
AttachmentType_ID_CARD AttachmentType = "ID_CARD"
AttachmentType_PASSPORT AttachmentType = "PASSPORT"
AttachmentType_DRIVING_LICENSE AttachmentType = "DRIVING_LICENSE"
AttachmentType_CPF AttachmentType = "CPF"
AttachmentType_CNPJ AttachmentType = "CNPJ"
)
6 changes: 6 additions & 0 deletions com/alipay/api/model/AuthorizationError.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package model

type AuthorizationError struct {
ErrorCode string `json:"errorCode,omitempty"`
ErrorMessage string `json:"errorMessage,omitempty"`
}
12 changes: 6 additions & 6 deletions com/alipay/api/model/Certificate.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package model

type Certificate struct {
CertificateType CertificateType `json:"certificate_type,omitempty"`
CertificateNo string `json:"certificate_no,omitempty"`
HolderName *UserName `json:"holder_name,omitempty"`
FileKeys []string `json:"file_keys,omitempty"`
CertificateAuthority string `json:"certificate_authority,omitempty"`
GrantType string `json:"grant_type,omitempty"`
CertificateType CertificateType `json:"certificateType,omitempty"`
CertificateNo string `json:"certificateNo,omitempty"`
HolderName *UserName `json:"holderName,omitempty"`
FileKeys []string `json:"fileKeys,omitempty"`
CertificateAuthority string `json:"certificateAuthority,omitempty"`
GrantType string `json:"grantType,omitempty"`
}

type CertificateType string
Expand Down
15 changes: 15 additions & 0 deletions com/alipay/api/model/DisputeEvidenceFormatType.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package model

type DisputeEvidenceFormatType string

const (
DisputeEvidenceFormatType_PDF DisputeEvidenceFormatType = "PDF"
DisputeEvidenceFormatType_WORD DisputeEvidenceFormatType = "WORD"
)

type DisputeEvidenceType string

const (
DisputeEvidenceType_DISPUTE_EVIDENCE_TEMPLATE DisputeEvidenceType = "DISPUTE_EVIDENCE_TEMPLATE"
DisputeEvidenceType_DISPUTE_EVIDENCE_FILE DisputeEvidenceType = "DISPUTE_EVIDENCE_FILE"
)
126 changes: 126 additions & 0 deletions com/alipay/api/model/MerchantInfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package model

type MerchantInfo struct {
ReferenceMerchantId string `json:"referenceMerchantId,omitempty"`
LoginId string `json:"loginId,omitempty"`
LegalEntityType LegalEntityType `json:"legalEntityType,omitempty"`
Company *Company `json:"company,omitempty"`
BusinessInfo *BusinessInfo `json:"businessInfo,omitempty"`
EntityAssociations []*EntityAssociations `json:"entityAssociations,omitempty"`
}

type LegalEntityType string

const (
LegalEntityType_Company LegalEntityType = "COMPANY"
LegalEntityType_INDIVIDUAL LegalEntityType = "INDIVIDUAL"
)

type Company struct {
LegalName string `json:"legalName,omitempty"`
CompanyType CompanyType `json:"companyType,omitempty"`
RegisteredAddress *Address `json:"registeredAddress,omitempty"`
OperatingAddress *Address `json:"operatingAddress,omitempty"`
IncorporationDate string `json:"incorporationDate,omitempty"`
StockInfo *StockInfo `json:"stockInfo,omitempty"`
Certificates *Certificate `json:"certificates,omitempty"`
Attachments []*Attachment `json:"attachments,omitempty"`
CompanyUnit *CompanyUnitType `json:"companyUnit,omitempty"`
Contacts []*Contact `json:"contacts,omitempty"`
VatNo string `json:"vatNo,omitempty"`
}

type BusinessInfo struct {
Mcc string `json:"mcc,omitempty"`
Websites []*WebSite `json:"websites,omitempty"`
EnglishName string `json:"englishName,omitempty"`
DoingBusinessAs string `json:"doingBusinessAs,omitempty"`
MainSalesCountry string `json:"mainSalesCountry,omitempty"`
AppName string `json:"appName,omitempty"`
ServiceDescription string `json:"serviceDescription,omitempty"`
}

type EntityAssociations struct {
AssociationType AssociationType `json:"associationType,omitempty"`
LegalEntityType LegalEntityType `json:"legalEntityType,omitempty"`
Company *Company `json:"company,omitempty"`
Individual *Individual `json:"individual,omitempty"`
ShareholdingRatio string `json:"shareholdingRatio,omitempty"`
}

type Individual struct {
Name *UserName `json:"name,omitempty"`
EnglishName *UserName `json:"englishName,omitempty"`
DateOfBirth string `json:"dateOfBirth,omitempty"`
PlaceOfBirth *Address `json:"placeOfBirth,omitempty"`
Certificates *Certificate `json:"certificates,omitempty"`
Nationality string `json:"nationality,omitempty"`
Contacts []*Contact `json:"contacts,omitempty"`
}

type AssociationType string

const (
AssociationType_LEGAL_REPRESENTATIVE AssociationType = "LEGAL_REPRESENTATIVE"
AssociationType_UBO AssociationType = "UBO"
AssociationType_CONTACT AssociationType = "CONTACT"
AssociationType_DIRECTOR AssociationType = "DIRECTOR"
AssociationType_AUTHORIZER AssociationType = "AUTHORIZER"
AssociationType_BOARD_MEMBER AssociationType = "BOARD_MEMBER"
)

type WebSite struct {
Name string `json:"name,omitempty"`
Url string `json:"url,omitempty"`
Desc string `json:"desc,omitempty"`
Type string `json:"type,omitempty"`
}

type StockInfo struct {
ListedRegion string `json:"listedRegion,omitempty"`
TickerSymbol string `json:"tickerSymbol,omitempty"`
}

type Attachment struct {
AttachmentType AttachmentType `json:"attachmentType,omitempty"`
File string `json:"file,omitempty"`
AttachmentName string `json:"attachmentName,omitempty"`
FileKey string `json:"fileKey,omitempty"`
}

type CompanyUnitType string

const (
CompanyUnitType_HEADQUARTER CompanyUnitType = "HEADQUARTER"
CompanyUnitType_BRANCH CompanyUnitType = "BRANCH"
)

type CompanyType string

const (
CompanyType_ENTERPRISE CompanyType = "ENTERPRISE"
CompanyType_SOLE_PROPRIETORSHIP CompanyType = "SOLE_PROPRIETORSHIP"
CompanyType_PARTNERSHIP CompanyType = "PARTNERSHIP"
CompanyType_STATE_OWNED_BUSINESS CompanyType = "STATE_OWNED_BUSINESS"
CompanyType_PRIVATELY_OWNED_BUSINESS CompanyType = "PRIVATELY_OWNED_BUSINESS"
CompanyType_PUBLICLY_LISTED_BUSINESS CompanyType = "PUBLICLY_LISTED_BUSINESS"
CompanyType_LTDA CompanyType = "LTDA"
CompanyType_SA CompanyType = "SA"
CompanyType_EIRELI CompanyType = "EIRELI"
CompanyType_BOFC CompanyType = "BOFC"
CompanyType_MEI CompanyType = "MEI"
CompanyType_EI CompanyType = "EI"
)

type Contact struct {
Type ContactType `json:"type,omitempty"`
Info string `json:"info,omitempty"`
}

type ContactType string

const (
ContactType_EMAIL ContactType = "EMAIL"
ContactType_PHONE_NO ContactType = "PHONE_NO"
ContactType_COMMERCIAL_PHONE_NO ContactType = "COMMERCIAL_PHONE_NO"
)
8 changes: 4 additions & 4 deletions com/alipay/api/model/Order.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ type Buyer struct {
BuyerPhoneNo string `json:"buyerPhoneNo,omitempty"`
BuyerEmail string `json:"buyerEmail,omitempty"`
BuyerRegistrationTime string `json:"buyerRegistrationTime,omitempty"`

IsAccountVerified *bool `json:"isAccountVerified,omitempty"`
SuccessfulOrderCount *int `json:"successfulOrderCount,omitempty"`
IsAccountVerified *bool `json:"isAccountVerified,omitempty"`
SuccessfulOrderCount *int `json:"successfulOrderCount,omitempty"`
}

type BrowserInfo struct {
Expand Down Expand Up @@ -123,7 +122,7 @@ type Address struct {
City string `json:"city,omitempty"`
Address1 string `json:"address1,omitempty"`
Address2 string `json:"address2,omitempty"`
ZipCode string `json:"zip_code,omitempty"`
ZipCode string `json:"zipCode,omitempty"`
Label string `json:"label,omitempty"`
}

Expand Down Expand Up @@ -164,4 +163,5 @@ type Order struct {
Transit *Transit `json:"transit,omitempty"`
Lodging *Lodging `json:"lodging,omitempty"`
Gaming *Gaming `json:"gaming,omitempty"`
OrderCreatedTime string `json:"orderCreatedTime,omitempty"`
}
13 changes: 13 additions & 0 deletions com/alipay/api/model/PaymentDetail.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package model

type PaymentDetail struct {
Amount *Amount `json:"amount,omitempty"`
PaymentMethod *PaymentMethod `json:"paymentMethod,omitempty"`
}

type AuthorizationPhase string

const (
AuthorizationPhase_PRE_AUTHORIZATION AuthorizationPhase = "PRE_AUTHORIZATION"
AuthorizationPhase_POST_AUTHORIZATION AuthorizationPhase = "POST_AUTHORIZATION"
)
Loading

0 comments on commit a458796

Please sign in to comment.