6
6
"encoding/json"
7
7
"errors"
8
8
"fmt"
9
- "io/ioutil "
9
+ "io"
10
10
"net/http"
11
11
"net/url"
12
12
"strings"
@@ -29,7 +29,7 @@ var applicationAccessTokens = make(map[[16]byte]ApplicationAccessToken)
29
29
var applicationAccessTokensLock sync.Mutex
30
30
31
31
// ApplicationAccessToken model, received from HMS OAuth API
32
- // https://developer.huawei.com/consumer/en/doc/HMSCore-Guides-V5 /open-platform-oauth-0000001050123437-V5 #EN-US_TOPIC_0000001050123437__section12493191334711
32
+ // https://developer.huawei.com/consumer/en/doc/HMSCore-Guides/open-platform-oauth-0000001050123437#EN-US_TOPIC_0000001050123437__section12493191334711
33
33
type ApplicationAccessToken struct {
34
34
// App-level access token.
35
35
AccessToken string `json:"access_token"`
@@ -62,7 +62,7 @@ type Client struct {
62
62
// If orderSiteURL or subscriptionSiteURL are not set, default to AppTouch Germany site.
63
63
//
64
64
// Please refer https://developer.huawei.com/consumer/en/doc/start/api-console-guide
65
- // and https://developer.huawei.com/consumer/en/doc/HMSCore-References-V5 /api-common-statement-0000001050986127-V5 for details.
65
+ // and https://developer.huawei.com/consumer/en/doc/HMSCore-References/api-common-statement-0000001050986127 for details.
66
66
func New (clientID , clientSecret , orderSiteURL , subscriptionSiteURL string ) * Client {
67
67
// Set default order / subscription iap site to AppTouch Germany if it is not provided
68
68
if ! strings .HasPrefix (orderSiteURL , "http" ) {
@@ -91,7 +91,7 @@ func New(clientID, clientSecret, orderSiteURL, subscriptionSiteURL string) *Clie
91
91
func (c * Client ) GetApplicationAccessTokenHeader () (string , error ) {
92
92
// To complie with the rate limit (1000/5min as of July 24th, 2020)
93
93
// new AccessTokens are requested only when it is expired.
94
- // Please refer https://developer.huawei.com/consumer/en/doc/HMSCore-Guides-V5 /open-platform-oauth-0000001050123437-V5 for detailes
94
+ // Please refer https://developer.huawei.com/consumer/en/doc/HMSCore-Guides/open-platform-oauth-0000001050123437 for detailes
95
95
if applicationAccessTokens [c .clientIDSecretHash ].ExpiredAt > time .Now ().Unix () {
96
96
return applicationAccessTokens [c .clientIDSecretHash ].HeaderString , nil
97
97
}
@@ -102,7 +102,7 @@ func (c *Client) GetApplicationAccessTokenHeader() (string, error) {
102
102
return "" , err
103
103
}
104
104
defer resp .Body .Close ()
105
- bodyBytes , err := ioutil .ReadAll (resp .Body )
105
+ bodyBytes , err := io .ReadAll (resp .Body )
106
106
if err != nil {
107
107
return "" , err
108
108
}
@@ -136,7 +136,13 @@ func (c *Client) GetApplicationAccessTokenHeader() (string, error) {
136
136
func (c * Client ) getRootOrderURLByFlag (flag int64 ) string {
137
137
switch flag {
138
138
case 1 :
139
- return "https://orders-at-dre.iap.dbankcloud.com"
139
+ return "https://orders-drcn.iap.cloud.huawei.com.cn"
140
+ case 2 :
141
+ return "https://orders-dre.iap.cloud.huawei.eu"
142
+ case 3 :
143
+ return "https://orders-dra.iap.cloud.huawei.asia"
144
+ case 4 :
145
+ return "https://orders-drru.iap.cloud.huawei.ru"
140
146
}
141
147
return c .orderSiteURL
142
148
}
@@ -145,7 +151,13 @@ func (c *Client) getRootOrderURLByFlag(flag int64) string {
145
151
func (c * Client ) getRootSubscriptionURLByFlag (flag int64 ) string {
146
152
switch flag {
147
153
case 1 :
148
- return "https://subscr-at-dre.iap.dbankcloud.com"
154
+ return "https://subscr-drcn.iap.cloud.huawei.com.cn"
155
+ case 2 :
156
+ return "https://subscr-dre.iap.cloud.huawei.eu"
157
+ case 3 :
158
+ return "https://subscr-dra.iap.cloud.huawei.asia"
159
+ case 4 :
160
+ return "https://subscr-drru.iap.cloud.huawei.ru"
149
161
}
150
162
return c .subscriptionSiteURL
151
163
}
@@ -176,33 +188,33 @@ func (c *Client) getResponseErrorByCode(code string) error {
176
188
var ErrorResponseUnknown error = errors .New ("Unknown error from API response" )
177
189
178
190
// ErrorResponseSignatureVerifyFailed failed to verify dataSignature against the response json string.
179
- // https://developer.huawei.com/consumer/en/doc/HMSCore-Guides-V5 /verifying-signature-returned-result-0000001050033088-V5
191
+ // https://developer.huawei.com/consumer/en/doc/HMSCore-Guides/verifying-signature-returned-result-0000001050033088
180
192
// var ErrorResponseSignatureVerifyFailed error = errors.New("Failed to verify dataSignature against the response json string")
181
193
182
194
// ErrorResponseInvalidParameter The parameter passed to the API is invalid.
183
195
// This error may also indicate that an agreement is not signed or parameters are not set correctly for the in-app purchase settlement in HUAWEI IAP, or the required permission is not in the list.
184
196
//
185
197
// Check whether the parameter passed to the API is correctly set. If so, check whether required settings in HUAWEI IAP are correctly configured.
186
- // https://developer.huawei.com/consumer/en/doc/HMSCore-References-V5 /server-error-code-0000001050166248-V5
198
+ // https://developer.huawei.com/consumer/en/doc/HMSCore-References/server-error-code-0000001050166248
187
199
var ErrorResponseInvalidParameter error = errors .New ("The parameter passed to the API is invalid" )
188
200
189
201
// ErrorResponseCritical A critical error occurs during API operations.
190
202
//
191
203
// Rectify the fault based on the error information in the response. If the fault persists, contact Huawei technical support.
192
- // https://developer.huawei.com/consumer/en/doc/HMSCore-References-V5 /server-error-code-0000001050166248-V5
204
+ // https://developer.huawei.com/consumer/en/doc/HMSCore-References/server-error-code-0000001050166248
193
205
var ErrorResponseCritical error = errors .New ("A critical error occurs during API operations" )
194
206
195
207
// ErrorResponseProductNotBelongToUser A user failed to consume or confirm a product because the user does not own the product.
196
208
//
197
- // https://developer.huawei.com/consumer/en/doc/HMSCore-References-V5 /server-error-code-0000001050166248-V5
209
+ // https://developer.huawei.com/consumer/en/doc/HMSCore-References/server-error-code-0000001050166248
198
210
var ErrorResponseProductNotBelongToUser error = errors .New ("A user failed to consume or confirm a product because the user does not own the product" )
199
211
200
212
// ErrorResponseConsumedProduct The product cannot be consumed or confirmed because it has been consumed or confirmed.
201
213
//
202
- // https://developer.huawei.com/consumer/en/doc/HMSCore-References-V5 /server-error-code-0000001050166248-V5
214
+ // https://developer.huawei.com/consumer/en/doc/HMSCore-References/server-error-code-0000001050166248
203
215
var ErrorResponseConsumedProduct error = errors .New ("The product cannot be consumed or confirmed because it has been consumed or confirmed" )
204
216
205
217
// ErrorResponseAbnormalUserAccount The user account is abnormal, for example, the user has been deregistered.
206
218
//
207
- // https://developer.huawei.com/consumer/en/doc/HMSCore-References-V5 /server-error-code-0000001050166248-V5
219
+ // https://developer.huawei.com/consumer/en/doc/HMSCore-References/server-error-code-0000001050166248
208
220
var ErrorResponseAbnormalUserAccount error = errors .New ("The user account is abnormal, for example, the user has been deregistered" )
0 commit comments