Documentation ¶
Index ¶
- Constants
- Variables
- func Parse(payload string, v interface{}) error
- func SignJwt(cfg *Config) (string, error)
- type AppError
- type Client
- type Config
- type ConsumptionRequest
- type ExtendRenewalDateRequest
- type ExtendRenewalDateResponse
- type HistoryResponse
- type JWSRenewalInfoDecodedPayload
- type JWSTransactionDecodedPayload
- type LastTransaction
- type OrderLookupResponse
- type RefundLookupResponse
- type StatusData
- type StatusResponse
Constants ¶
const ( Production env = "production" Development env = "development" )
Variables ¶
var ( ErrPrivateKeyNotValidPEM = errors.New("pk is not a valid PEM type") ErrPrivateKeyNotValidPKCS8 = errors.New("pk must be a encoded PKCS#8 type") ErrPrivateKeyNotECDSA = errors.New("pk must be of ECDSA type") )
var ( ErrConfigIsNil = errors.New("config is nil") ErrConfigInvalid = errors.New("config invalid") ErrRequestFailed = errors.New("request failed") )
var ( AccountNotFoundRetryableError = newAppError(4040002, "Account not found. Please try again") AppNotFoundRetryableError = newAppError(4040004, "AccountNotFoundRetryableError") GeneralInternalRetryableError = newAppError(5000001, "An unknown error occurred. Please try again") OriginalTransactionIdNotFoundRetryableError = newAppError(4040006, "Original transaction id not found. Please try again") )
可重试错误 Retryable Errors
var ( AccountNotFoundError = newAppError(4040001, "Account not found") AppNotFoundError = newAppError(4040003, "App not found") GeneralInternalError = newAppError(5000000, "An unknown error occurred") GeneralBadRequestError = newAppError(4000000, "Bad request") InvalidAppIdentifierError = newAppError(4000002, "Invalid request app identifier") InvalidExtendByDaysError = newAppError(4000009, "Invalid extend by days value") InvalidExtendReasonCodeError = newAppError(4000010, "Invalid extend reason code") InvalidOriginalTransactionIdError = newAppError(4000008, "Invalid original transaction id") InvalidRequestIdentifierError = newAppError(4000011, "Invalid request identifier") InvalidRequestRevisionError = newAppError(4000005, "Invalid request revision") OriginalTransactionIdNotFoundError = newAppError(4040005, "Original transaction id not found") SubscriptionExtensionIneligibleError = newAppError(4030004, "Forbidden - subscription state ineligible for extension") SubscriptionMaxExtensionError = newAppError(4030005, "Forbidden - subscription has reached maximum extension count") )
其他错误 Errors
Functions ¶
func SignJwt ¶
SignJwt Sign the JWT 创建签名: https://jwt.io/ iss: 发行人: 您在 App Store Connect 中的密钥页面中的发行者 ID(例如:" 57246542-96fe-1a63-e053-0824d011072a") Issuer: Your issuer ID from the Keys page in App Store Connect (Ex: "57246542-96fe-1a63-e053-0824d011072a") kid: 秘钥:您在 App Store Connect 中的私钥 ID(例如2X9R4HXF34:) Key ID: Your private key ID from App Store Connect (Ex: 2X9R4HXF34) bid: 应用的BundleID(例如:“com.example.testbundleid2021”) Bundle ID: Your app’s bundle ID (Ex: “com.example.testbundleid2021”) pk: 签名的秘钥 sign key
Types ¶
type Client ¶
type Client interface { // ApiGetAllSubscriptionStatuses 获取所有的订阅状态 // Get All Subscription Statuses // doc: https://developer.apple.com/documentation/appstoreserverapi/get_all_subscription_statuses ApiGetAllSubscriptionStatuses(transactionId string) (*StatusResponse, error) // ApiLookUpOrderId 查找订单 ID // Look Up Order ID // doc: https://developer.apple.com/documentation/appstoreserverapi/look_up_order_id ApiLookUpOrderId(orderId string) (*OrderLookupResponse, error) // ApiGetTransactionHistory 获取历史交易记录 // Get Transaction History // doc: https://developer.apple.com/documentation/appstoreserverapi/get_transaction_history // desc: true then signedTransactions order by webOrderLineItemId desc ApiGetTransactionHistory(transactionId string, desc bool) (*HistoryResponse, error) // ApiGetRefundHistory 获取退款历史 // Get Refund History // doc: https://developer.apple.com/documentation/appstoreserverapi/get_refund_history // desc: true then signedTransactions order by webOrderLineItemId desc ApiGetRefundHistory(transactionId string, desc bool) (*RefundLookupResponse, error) // ApiExtendAsubscriptionRenewalDate 延长订阅续订日期 // Extend a Subscription Renewal Date // doc: https://developer.apple.com/documentation/appstoreserverapi/extend_a_subscription_renewal_date ApiExtendAsubscriptionRenewalDate(transactionId string, req ExtendRenewalDateRequest) (*ExtendRenewalDateResponse, error) // ApiSendConsumptionInformation 发送消费信息 // Send Consumption Information // doc: https://developer.apple.com/documentation/appstoreserverapi/send_consumption_information ApiSendConsumptionInformation(transactionId string, req ConsumptionRequest) error }
type Config ¶
type Config struct { // 发行人: 您在 App Store Connect 中的密钥页面中的发行者 ID(例如:" 57246542-96fe-1a63-e053-0824d011072a") // Issuer: Your issuer ID from the Keys page in App Store Connect (Ex: "57246542-96fe-1a63-e053-0824d011072a") Iss string // 秘钥:您在 App Store Connect 中的私钥 ID(例如2X9R4HXF34:) // Key ID: Your private key ID from App Store Connect (Ex: 2X9R4HXF34) Kid string // 应用的BundleID(例如:“com.example.testbundleid2021”) // Bundle ID: Your app’s bundle ID (Ex: “com.example.testbundleid2021”) Bid string // 签名的秘钥 // sign private key, eg: /* -----BEGIN PRIVATE KEY----- MIGTAg23kjjh2h3uhuhfduhJHAKJ23JASjhaskjj234hjHKJHS31hkjj -----END PRIVATE KEY-----` */ Pk string // 受众:appstoreconnect-v1 // Audience: appstoreconnect-v1 Aud string // 有效期:默认是10分钟 ExpiryIn time.Duration // 环境:默认正式环境 Evn env // 重试次数:默认10次 TryCount uint // contains filtered or unexported fields }
type ConsumptionRequest ¶
type ConsumptionRequest struct { AccountTenure uint8 `json:"accountTenure"` AppAccountToken string `json:"appAccountToken"` ConsumptionStatus uint8 `json:"consumptionStatus"` CustomerConsented bool `json:"customerConsented"` DeliveryStatus uint8 `json:"deliveryStatus"` LifetimeDollarsPurchased uint8 `json:"lifetimeDollarsPurchased"` LifetimeDollarsRefunded uint8 `json:"lifetimeDollarsRefunded"` Platform uint8 `json:"platform"` PlayTime uint8 `json:"playTime"` SampleContentProvided bool `json:"sampleContentProvided"` UserStatus uint8 `json:"userStatus"` }
ConsumptionRequest 消费请求 doc: https://developer.apple.com/documentation/appstoreserverapi/consumptionrequest
type ExtendRenewalDateRequest ¶
type ExtendRenewalDateRequest struct { // 必填。延长订阅续订日期的天数。最大值为 90 天。 // Required. // The number of days to extend the subscription renewal date. // The maximum value is 90 days. ExtendByDays uint8 `json:"extendByDays"` // 必填。订阅日期延长的原因代码。 // Required. // The reason code for the subscription date extension. ExtendReasonCode uint8 `json:"extendReasonCode"` // 必填。一个字符串,其中包含您提供的用于唯一标识此续订日期扩展请求的值。 // 字符串的最大长度为 128 个字符。 // Required. // A string that contains a value you provide to uniquely identify this renewal-date-extension request. // The maximum length of the string is 128 characters. RequestIdentifier string `json:"requestIdentifier"` }
type ExtendRenewalDateResponse ¶
type ExtendRenewalDateResponse struct { EffectiveDate int64 `json:"effectiveDate"` OriginalTransactionId string `json:"originalTransactionId"` Success bool `json:"success"` WebOrderLineItemId string `json:"webOrderLineItemId"` // contains filtered or unexported fields }
func (*ExtendRenewalDateResponse) Raw ¶
func (r *ExtendRenewalDateResponse) Raw() string
type HistoryResponse ¶
type HistoryResponse struct { Revision string `json:"revision"` BundleId string `json:"bundleId"` AppAppleId int64 `json:"appAppleId"` Environment string `json:"environment"` HasMore bool `json:"hasMore"` SignedTransactions []JWSTransactionDecodedPayload `json:"signedTransactions"` // contains filtered or unexported fields }
func (*HistoryResponse) Raw ¶
func (r *HistoryResponse) Raw() string
type JWSRenewalInfoDecodedPayload ¶
type JWSRenewalInfoDecodedPayload struct { AutoRenewProductId string `json:"autoRenewProductId,omitempty"` AutoRenewStatus int64 `json:"autoRenewStatus,omitempty"` Environment string `json:"environment,omitempty"` ExpirationIntent int64 `json:"expirationIntent,omitempty"` GracePeriodExpiresDate int64 `json:"gracePeriodExpiresDate,omitempty"` IsInBillingRetryPeriod bool `json:"isInBillingRetryPeriod,omitempty"` OfferIdentifier string `json:"offerIdentifier,omitempty"` OfferType int64 `json:"offerType,omitempty"` OriginalTransactionId string `json:"originalTransactionId,omitempty"` PriceIncreaseStatus int64 `json:"priceIncreaseStatus,omitempty"` ProductId string `json:"productId,omitempty"` SignedDate int64 `json:"signedDate,omitempty"` }
JWSRenewalInfoDecodedPayload JWSRenewal信息解码负载 doc: https://developer.apple.com/documentation/appstoreserverapi/jwsrenewalinfodecodedpayload
type JWSTransactionDecodedPayload ¶
type JWSTransactionDecodedPayload struct { AppAccountToken string `json:"appAccountToken,omitempty"` BundleId string `json:"bundleId,omitempty"` Environment string `json:"environment,omitempty"` ExpiresDate int64 `json:"expiresDate,omitempty"` InAppOwnershipType string `json:"inAppOwnershipType,omitempty"` IsUpgraded bool `json:"isUpgraded"` OfferIdentifier string `json:"offerIdentifier"` OfferType int64 `json:"offerType,omitempty"` OriginalPurchaseDate int64 `json:"originalPurchaseDate,omitempty"` OriginalTransactionId string `json:"originalTransactionId,omitempty"` ProductId string `json:"productId,omitempty"` PurchaseDate int64 `json:"purchaseDate,omitempty"` Quantity int64 `json:"quantity,omitempty"` RevocationDate int64 `json:"revocationDate,omitempty"` RevocationReason int64 `json:"revocationReason,omitempty"` SignedDate int64 `json:"signedDate,omitempty"` SubscriptionGroupIdentifier string `json:"subscriptionGroupIdentifier"` TransactionId string `json:"transactionId,omitempty"` Type string `json:"type,omitempty"` WebOrderLineItemId string `json:"webOrderLineItemId,omitempty"` }
JWSTransactionDecodedPayload JWSTransaction解码的有效负载 doc: https://developer.apple.com/documentation/appstoreserverapi/jwstransactiondecodedpayload
type LastTransaction ¶
type LastTransaction struct { OriginalTransactionId string `json:"originalTransactionId"` Status int64 `json:"status"` SignedTransactionInfo JWSTransactionDecodedPayload `json:"signedTransactionInfo"` SignedRenewalInfo JWSRenewalInfoDecodedPayload `json:"signedRenewalInfo"` }
type OrderLookupResponse ¶
type OrderLookupResponse struct { Status int64 `json:"status"` // 原始数据 SignedTransactions []JWSTransactionDecodedPayload `json:"signedTransactions"` // contains filtered or unexported fields }
func (*OrderLookupResponse) Raw ¶
func (r *OrderLookupResponse) Raw() string
type RefundLookupResponse ¶
type RefundLookupResponse struct { SignedTransactions []JWSTransactionDecodedPayload `json:"signedTransactions"` // contains filtered or unexported fields }
func (*RefundLookupResponse) Raw ¶
func (r *RefundLookupResponse) Raw() string
type StatusData ¶
type StatusData struct { SubscriptionGroupIdentifier string `json:"subscriptionGroupIdentifier"` LastTransactions []LastTransaction `json:"lastTransactions"` }
type StatusResponse ¶
type StatusResponse struct { Environment string `json:"environment"` BundleId string `json:"bundleId"` AppAppleId int64 `json:"appAppleId"` Data []StatusData `json:"data"` // contains filtered or unexported fields }