Fedex 新接口测试对接

1.进入FedEx官网​​https://www.fedex.com,在底部点击进去开发者中心。​

2.登陆

3.点击我的项目新建项目,勾选需要的api

4.接受条款

5.配置项目

6.创建完成就可以获取到测试账号

请求地址:​​​https://apis-sandbox.fedex.com​​ API密钥 秘密密钥

7.获取access_token

java请求

Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.post("https://apis-sandbox.fedex.com/oauth/token")
.header("Content-Type", "application/x-www-form-urlencoded")
.field("grant_type", "client_credentials")
.field("client_id", "l764f8bb5b832f4d30ad11272f599a04a2")
.field("client_secret", "836a1ea50ece4cc1a47e89abbe6b4246")
.asString();

php请求

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => 'https://apis-sandbox.fedex.com/oauth/token',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => 'grant_type=client_credentials&client_id=l764f8bb5b832f4d30ad11272f599a04a2&client_secret=836a1ea50ece4cc1a47e89abbe6b4246',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/x-www-form-urlencoded'
),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

go请求

package main

import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)

func main() {

url := "https://apis-sandbox.fedex.com/oauth/token"
method := "POST"

payload := strings.NewReader("grant_type=client_credentials&client_id=l764f8bb5b832f4d30ad11272f599a04a2&client_secret=836a1ea50ece4cc1a47e89abbe6b4246")

client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)

if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()

body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}

8.用access_token请求接口

java请求

Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.post("https://apis-sandbox.fedex.com/country/v1/postal/validate")
.header("Content-Type", "application/json")
.header("authorization", "bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY29wZSI6WyJDWFMiLCJTRUNVUkUiXSwiUGF5bG9hZCI6ImFLcEpEZEJ1MXN4WmY3bEpFOUxxd2g3OEFCZ3FCSzcxa2hvdkRnWHpWWUw3R2VDSmxHbFY5ZlpjbVBBNUNrZlNnTGJ0UTFSUWpyOTBWK2x6K1UvN2liWXBPQzdlemxjS1czbW5mOUpXTms1SnpXSVAwQlF4UlFsN0FCMjJOdUNwZHVnNTNuV0d0RzVFQTltR3lET2NCcityeSswMkpUd0c4R3RDS1BYa05uQTFFbEgycCtDWHRBK3FTcjN2Nnc0OWp6YzNZMUMvQ3o3RFhCdm1DUkN5dXpVeHY5Y0hzMEIzdnV3cUlRbXFiSlBSVVAyaWljS1JyY3RYTHczOWZqdFZXTHVud1FHZ0xtYk5YMWVyb21oSVEvaHJRQzZMWTJwTHd0bGFaRkdRVzNFPSIsImV4cCI6MTY1MDk2NzI3OSwianRpIjoiNWM3ZDk3YTctZTQ1My00NzAxLWFlMTMtYjVhY2JhYThmMjcwIiwiY2xpZW50X2lkIjoibDc2NGY4YmI1YjgzMmY0ZDMwYWQxMTI3MmY1OTlhMDRhMiJ9.O-kgvrc3vr8-XZBvwnmW1MweGdw4V5UiiiCO2LK9qWeHbAs7TgN5bkrYhaJ5oY7WkVEQkAdURZfpZb02sUrNwXDu6p77srSrY82zVyr1Av6yyhCg4NEmKp-9Nk5zyNJULN3LrYqunRol8o8b1N6p8rJt3Kwm7HQxYegDe2LS8oYALNNU3Y9uZV4E_DVOQePRUDg0zKNzaQQwoQW-mj_TenLjNsYWyEii6sp5GH43HPjGpiR3P2GzM5amO1ffeTjVP4ym-_B1xY1VN9uN6KVvvU9iiJ_sqjTI_Up82-SoUd1C_3ASHJvc-8xg-NFOng8aIebYFwuPDWElg5ZBSf1rYHT_fVS_GN6nTlGvb1b5sE0q0redKvUzStrOm1j-aNsfJbK3AG7JrLEp32YOse6-6-_etKH2r29rI_N2yxzG06ANL5Tsj4QA5Z_pK3efkmqE0c5cvFZm1ljYGPiPihOmempoTnUSykn4vp8blkpnmZ_YhG3xjb4ePdqCyk9Ac94Kg9f-qCCKA1MDGfGB-GbYxcqjwJdcJz5wiF1QItm6vFkhJzeKZeWnZdQOPSQyT_922CMxZOJAn_7wcpUSeaGDHjMHNKQkJdhUIjVlydcLEF_N6nk8IbIvZQ2s8QrG3tFECMT5Nc2qa-M9LXCa4Z80KKKkubP5APMSVGseXa4mJw8")
.body("{\r\n\"carrierCode\": \"FDXG\",\r\n\"countryCode\": \"US\",\r\n\"stateOrProvinceCode\": \"US\",\r\n\"postalCode\": \"502267\",\r\n\"shipDate\": \"2019-10-04\",\r\n\"routingCode\": \"Memphis 38017 - HKA/NQA\",\r\n\"checkForMismatch\": true\r\n}")
.asString();

php请求

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => 'https://apis-sandbox.fedex.com/country/v1/postal/validate',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"carrierCode": "FDXG",
"countryCode": "US",
"stateOrProvinceCode": "US",
"postalCode": "502267",
"shipDate": "2019-10-04",
"routingCode": "Memphis 38017 - HKA/NQA",
"checkForMismatch": true
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'authorization: bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY29wZSI6WyJDWFMiLCJTRUNVUkUiXSwiU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b4ePdqCyk9Ac94Kg9f-qCCKA1MDGfGB-GbYxcqjwJdcJz5wiF1QItm6vFkhJzeKZeWnZdQOPSQyT_922CMxZOJAn_7wcpUSeaGDHjMHNKQkJdhUIjVlydcLEF_N6nk8IbIvZQ2s8QrG3tFECMT5Nc2qa-M9LXCa4Z80KKKkubP5APMSVGseXa4mJw8'
),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

go请求

package main

import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)

func main() {

url := "https://apis-sandbox.fedex.com/country/v1/postal/validate"
method := "POST"

payload := strings.NewReader(`{`+"
"+`
"carrierCode": "FDXG",`+"
"+`
"countryCode": "US",`+"
"+`
"stateOrProvinceCode": "US",`+"
"+`
"postalCode": "502267",`+"
"+`
"shipDate": "2019-10-04",`+"
"+`
"routingCode": "Memphis 38017 - HKA/NQA",`+"
"+`
"checkForMismatch": true`+"
"+`
}`)

client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)

if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("authorization", "bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY29wZSI6WyJDWFMiLCJTRUNVUkUiXSwiUGF5bG9hZCI6ImFLcEpEZEJ1MXN4WmY3bEpFOUxxd2g3OEFCZ3FCSzcxa2hvdkRnWHpWWUw3R2VDSmxHbFY5ZlpjbVBBNUNrZlNnTGJ0UTFSUWpyOTBWK2x6K1UvN2liWXBPQzdlemxjS1czbW5mOUpXTms1SnpXSVAwQlF4UlFsN0FCMjJOdUNwZHVnNTNuV0d0RzVFQTltR3lET2NCcityeSswMkpUd0c4R3RDS1BYa05uQTFFbEgycCtDWHRBK3FTcjN2Nnc0OWp6YzNZMUMvQ3o3RFhCdm1DUkN5dXpVeHY5Y0hzMEIzdnV3cUlRbXFiSlBSVVAyaWljS1JyY3RYTHczOWZqdFZXTHVud1FHZ0xtYk5YMWVyb21oSVEvaHJRQzZMWTJwTHd0bGFaRkdRVzNFPSIsImV4cCI6MTY1MDk2NzI3OSwianRpIjoiNWM3ZDk3YTctZTQ1My00NzAxLWFlMTMtYjVhY2JhYThmMjcwIiwiY2xpZW50X2lkIjoibDc2NGY4YmI1YjgzMmY0ZDMwYWQxMTI3MmY1OTlhMDRhMiJ9.O-kgvrc3vr8-XZBvwnmW1MweGdw4V5UiiiCO2LK9qWeHbAs7TgN5bkrYhaJ5oY7WkVEQkAdURZfpZb02sUrNwXDu6p77srSrY82zVyr1Av6yyhCg4NEmKp-9Nk5zyNJULN3LrYqunRol8o8b1N6p8rJt3Kwm7HQxYegDe2LS8oYALNNU3Y9uZV4E_DVOQePRUDg0zKNzaQQwoQW-mj_TenLjNsYWyEii6sp5GH43HPjGpiR3P2GzM5amO1ffeTjVP4ym-_B1xY1VN9uN6KVvvU9iiJ_sqjTI_Up82-SoUd1C_3ASHJvc-8xg-NFOng8aIebYFwuPDWElg5ZBSf1rYHT_fVS_GN6nTlGvb1b5sE0q0redKvUzStrOm1j-aNsfJbK3AG7JrLEp32YOse6-6-_etKH2r29rI_N2yxzG06ANL5Tsj4QA5Z_pK3efkmqE0c5cvFZm1ljYGPiPihOmempoTnUSykn4vp8blkpnmZ_YhG3xjb4ePdqCyk9Ac94Kg9f-qCCKA1MDGfGB-GbYxcqjwJdcJz5wiF1QItm6vFkhJzeKZeWnZdQOPSQyT_922CMxZOJAn_7wcpUSeaGDHjMHNKQkJdhUIjVlydcLEF_N6nk8IbIvZQ2s8QrG3tFECMT5Nc2qa-M9LXCa4Z80KKKkubP5APMSVGseXa4mJw8")


res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()

body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}