Просмотр исходного кода

update support AliPaySystemOauthToken() Sanbox

Jerry 6 лет назад
Родитель
Сommit
3b93eb2683
2 измененных файлов с 14 добавлено и 7 удалено
  1. 1 1
      alipay_client.go
  2. 13 6
      alipay_service_api.go

+ 1 - 1
alipay_client.go

@@ -406,7 +406,7 @@ func (this *aliPayClient) AliPaySystemOauthToken(body BodyMap) (aliRsp *AliPaySy
 		return nil, errors.New("code and refresh_token are not allowed to be null at the same time")
 		return nil, errors.New("code and refresh_token are not allowed to be null at the same time")
 	}
 	}
 
 
-	bytes, err = aliPaySystemOauthToken(this.AppId, this.privateKey, body, "alipay.system.oauth.token")
+	bytes, err = aliPaySystemOauthToken(this.AppId, this.privateKey, body, "alipay.system.oauth.token", this.isProd)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}

+ 13 - 6
alipay_service_api.go

@@ -372,7 +372,7 @@ func AliPaySystemOauthToken(appId, privateKey, grantType, codeOrToken string) (r
 		body.Set("grant_type", "authorization_code")
 		body.Set("grant_type", "authorization_code")
 		body.Set("code", codeOrToken)
 		body.Set("code", codeOrToken)
 	}
 	}
-	bs, err = aliPaySystemOauthToken(appId, privateKey, body, "alipay.system.oauth.token")
+	bs, err = aliPaySystemOauthToken(appId, privateKey, body, "alipay.system.oauth.token", true)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
@@ -390,7 +390,7 @@ func AliPaySystemOauthToken(appId, privateKey, grantType, codeOrToken string) (r
 }
 }
 
 
 //向支付宝发送请求
 //向支付宝发送请求
-func aliPaySystemOauthToken(appId, privateKey string, body BodyMap, method string) (bytes []byte, err error) {
+func aliPaySystemOauthToken(appId, privateKey string, body BodyMap, method string, isProd bool) (bytes []byte, err error) {
 	//===============生成参数===================
 	//===============生成参数===================
 	body.Set("app_id", appId)
 	body.Set("app_id", appId)
 	body.Set("method", method)
 	body.Set("method", method)
@@ -412,10 +412,17 @@ func aliPaySystemOauthToken(appId, privateKey string, body BodyMap, method strin
 
 
 	var url string
 	var url string
 	agent := HttpAgent()
 	agent := HttpAgent()
-	//正式环境
-	url = zfb_base_url_utf8
-	//fmt.Println(url)
-	agent.Post(url)
+	if !isProd {
+		//沙箱环境
+		url = zfb_sanbox_base_url_utf8
+		//fmt.Println(url)
+		agent.Post(url)
+	} else {
+		//正式环境
+		url = zfb_base_url_utf8
+		//fmt.Println(url)
+		agent.Post(url)
+	}
 	_, bs, errs := agent.
 	_, bs, errs := agent.
 		Type("form-data").
 		Type("form-data").
 		SendString(urlParam).
 		SendString(urlParam).