SDK獲取
開發(fā)語言 |
資源下載 |
環(huán)境要求 |
JAVA版資源 |
SDK1.5 |
適用于Java語言、jdk版本1.5及以上的開發(fā)環(huán)境 |
|
SDK1.4 |
適用于Java語言、jdk版本1.4及以下的開發(fā)環(huán)境 |
.NET版資源 |
SDK |
適用于Visual studio 2010及以上版本、Framework3.5及以上版本的開發(fā)環(huán)境 |
PHP版資源 |
SDK |
適用于php5.5以上的開發(fā)環(huán)境 |
C++版資源 |
SDK |
適用于C++語言,使用方法詳見SDK中的Readme.txt |
C版資源 |
SDK |
適用于C語言,使用方法詳見SDK中的README.md(內(nèi)含當面付DEMO示例) |
SDK集成
- SDK已經(jīng)對加簽驗簽邏輯做了封裝,使用SDK可直接調(diào)用API。
- 確定接口對應(yīng)的類
例如接口名:alipay.offline.material.image.upload 在SDK中對應(yīng)的類為:每個單詞首字母大寫,并去掉分隔符(“.”),末尾加上Request(或Response) 如上接口名對應(yīng)的類為: AlipayOfflineMaterialImageUploadRequest(請求類) AlipayOfflineMaterialImageUploadResponse(響應(yīng)類) 具體調(diào)用方式見下方各語言。
JavaSDK集成示例
SDK包說明
- alipay-sdk-java*.jar—————————支付寶SDK編譯文件jar
- alipay-sdk-java*-source.jar——————支付寶SDK源碼文件jar
- commons-logging-1.1.1.jar——————SDK依賴的日志jar
- commons-logging-1.1.1-sources.jar———SDK依賴的日志源碼jar
注意
- 集成支付寶接口需要引入的文件是:
alipay-sdk-java*.jar commons-logging-1.1.1.jar - 若進一步了解代碼實現(xiàn)請引入文件:
alipay-sdk-java*-source.jar commons-logging-1.1.1-sources.jar
普通調(diào)用示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | AlipayOpenPublicTemplateMessageIndustryModifyRequest request = new AlipayOpenPublicTemplateMessageIndustryModifyRequest();
request.setBizContent(" {
"primary_industry_name" : "IT科技/IT軟件與服務(wù)" ,
"primary_industry_code" : "10001/20102" ,
"secondary_industry_code" : "10001/20102" ,
"secondary_industry_name" : "IT科技/IT軟件與服務(wù)"
}
");
AlipayOpenPublicTemplateMessageIndustryModifyResponse response = client.execute(request);
if (response.isSuccess()){
}
|
圖片上傳接口調(diào)用示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | AlipayOfflineMaterialImageUploadRequest request = new AlipayOfflineMaterialImageUploadRequest();
request.setImageName( "test" );
FileItem item = new FileItem( "C:/Downloads/ooopic_963991_7eea1f5426105f9e6069/16365_1271139700.jpg" );
request.setImageType( "JPG" );
request.setImageContent(item);
AlipayOfflineMaterialImageUploadResponse response = client.execute(request);
if (response.isSuccess()){
String imageUrl = response.getImageUrl();
}
|
用戶授權(quán)接口調(diào)用示例
1 2 3 4 5 6 7 | AlipayUserUserinfoShareRequest request = new AlipayUserUserinfoShareRequest();
AlipayUserUserinfoShareResponse response= client.execute(req, "accessToken" );
|
應(yīng)用授權(quán)接口調(diào)用示例(ISV代理商戶調(diào)用)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | AlipayOpenPublicTemplateMessageIndustryModifyRequest request = new AlipayOpenPublicTemplateMessageIndustryModifyRequest();
request.setBizContent(" {
"primary_industry_name" : "IT科技/IT軟件與服務(wù)" ,
"primary_industry_code" : "10001/20102" ,
"secondary_industry_code" : "10001/20102" ,
"secondary_industry_name" : "IT科技/IT軟件與服務(wù)"
}
");
request.putOtherTextParam( "app_auth_token" , "201511BBaaa6464f271f49e482f2e9fe63ca5F05" );
AlipayOpenPublicTemplateMessageIndustryModifyResponse response = client.execute(request);
if (response.isSuccess()){
}
|
.netSDK集成示例
普通調(diào)用示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | AlipayOpenPublicTemplateMessageIndustryModifyRequest request = new AlipayOpenPublicTemplateMessageIndustryModifyRequest();
request.BizContent="{
"primary_industry_name" : "IT科技/IT軟件與服務(wù)" ,
"primary_industry_code" : "10001/20102" ,
"secondary_industry_code" : "10001/20102" ,
"secondary_industry_name" : "IT科技/IT軟件與服務(wù)"
}";
AlipayOpenPublicTemplateMessageIndustryModifyResponse response = client.execute(request);
if (response.isSuccess()){
}
|
圖片上傳接口調(diào)用示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | AlipayOfflineMaterialImageUploadRequest request = new AlipayOfflineMaterialImageUploadRequest();
request.setImageName( "test" );
FileItem item = new FileItem( "C:/Downloads/ooopic_963991_7eea1f5426105f9e6069/16365_1271139700.jpg" );
request.setImageType( "JPG" );
request.setImageContent(item);
AlipayOfflineMaterialImageUploadResponse response = alipayClient.execute(request);
if (response.isSuccess()){
String imageUrl = response.getImageUrl();
}
|
用戶授權(quán)接口調(diào)用示例
1 2 3 4 5 6 7 | AlipayUserUserinfoShareRequest request = new AlipayUserUserinfoShareRequest();
AlipayUserUserinfoShareResponse response= client.execute(req, "accessToken" );
|
應(yīng)用授權(quán)接口調(diào)用示例(ISV代理商戶調(diào)用)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | AlipayOpenPublicTemplateMessageIndustryModifyRequest request = new AlipayOpenPublicTemplateMessageIndustryModifyRequest();
request.setBizContent(" {
"primary_industry_name" : "IT科技/IT軟件與服務(wù)" ,
"primary_industry_code" : "10001/20102" ,
"secondary_industry_code" : "10001/20102" ,
"secondary_industry_name" : "IT科技/IT軟件與服務(wù)"
}
");
AlipayOpenPublicTemplateMessageIndustryModifyResponse response = client.execute(request, null , "app_auth_token" );
if (response.isSuccess()){
}
|
phpSDK集成示例
普通調(diào)用示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | $c = new AopClient;
$c->appId = "app_id" ;
$c->privateKey = "your private_key" ;
$c->format = "json" ;
$c->charset= "GBK" ;
$c->alipayPublicKey = "alipay_public_key" ;
$req = new AlipayOpenPublicTemplateMessageIndustryModifyRequest();
$request->bizContent = "{
"primary_industry_name" : "IT科技/IT軟件與服務(wù)" ,
"primary_industry_code" : "10001/20102" ,
"secondary_industry_code" : "10001/20102" ,
"secondary_industry_name" : "IT科技/IT軟件與服務(wù)"
}";
$response= $c->execute($req);
|
圖片上傳接口調(diào)用示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | $c = new AopClient;
$c->appId = "app_id" ;
$c->privateKey = "your private_key" ;
$c->format = "json" ;
$c->charset = "GBK" ;
$c->alipayPublicKey = "alipay_public_key" ;
$request = new AlipayOfflineMaterialImageUploadRequest();
$request->setImageName( "測試文件" );
$request->setImageType( "jpg" );
$request->setImageContent( "@" . "本地文件路徑" );
$response = $c->execute($req);
$response->getImageUrl();
|
用戶授權(quán)接口調(diào)用示例
1 2 3 4 5 6 7 8 9 10 11 | $c = new AopClient;
$c->appId = "app_id" ;
$c->privateKey = "your private_key" ;
$c->format = "json" ;
$c->charset = "GBK" ;
$c->alipayPublicKey = "alipay_public_key" ;
$request= new AlipayUserUserinfoShareRequest();
$response= $c->execute($req, "accessToken" );
|
應(yīng)用授權(quán)接口調(diào)用示例(ISV代理商戶調(diào)用)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | $c = new AopClient;
$c->appId = "app_id" ;
$c->privateKey = "your private_key" ;
$c->format = "json" ;
$c->charset = "GBK" ;
$c->alipayPublicKey = "alipay_public_key" ;
##實例化具體API對應(yīng)的request類,類名稱和接口名稱對應(yīng),當前調(diào)用接口名稱:alipay.open. public .template.message.industry.modify
$request = new AlipayOpenPublicTemplateMessageIndustryModifyRequest();
$request->bizContent = "{
"primary_industry_name" : "IT科技/IT軟件與服務(wù)" ,
"primary_industry_code" : "10001/20102" ,
"secondary_industry_code" : "10001/20102" ,
"secondary_industry_name" : "IT科技/IT軟件與服務(wù)"
}";
$response= $c->execute($req,NULL, "app_auth_token" );
|
方法說明
加簽方法(如果不用SDK調(diào)用,推薦用該方法加簽)
1 2 3 4 5 6 | /**
@param params 參數(shù)列表 key-參數(shù)名稱 value-參數(shù)值
@param privateKey 加簽私鑰
@param charset 加簽字符集
**/
String AlipaySignature.rsaSign(Map<String, String> params, String privateKey, String charset)
|
驗簽方法(同步請求時,如果不用SDK調(diào)用,推薦用該方法驗簽)
1 2 3 4 5 6 7 | /**
@param content 待驗簽字符串
@param sign 簽名值
@param publicKey 驗簽公鑰
@param charset 驗簽字符集
**/
boolean AlipaySignature.rsaCheckContent(String content, String sign, String publicKey, String charset)
|
驗簽方法(例如異步通知的時候,用戶需要用到驗簽方法)
1 2 3 4 5 6 | /**
@param params 參數(shù)列表(包括待驗簽參數(shù)和簽名值sign) key-參數(shù)名稱 value-參數(shù)值
@param publicKey 驗簽公鑰
@param charset 驗簽字符集
**/
boolean AlipaySignature.rsaCheckV2(Map<String, String> params, String publicKey, String charset)
|
注意事項
- AlipayClient的實現(xiàn)類都是線程安全的,所以沒有必要每次API請求都新建一個AlipayClient實現(xiàn)類;
- 創(chuàng)建AlipayClient實現(xiàn)類的實例時,指定format=json,相比xml格式,可以減少數(shù)據(jù)傳輸量,提升API請求效率。
FAQ
關(guān)于此文檔暫時還沒有FAQ
|