PHP
单页接口
SDK下载
$url = 'https://url2pic.php127.com/api/url2pic';
$data = [
'key' => '您的key',
'url' => 'https://www.baidu.com',
'width' => 1440,
'type' => 'png'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
curl_close($ch);
$array = json_decode($output,true);
print_r($array);
批量接口
$url = 'https://url2pic.php127.com/api/url2pic/batch';
$data = [
'key' => '您的key',
'width' => 1440,
'type' => 'png',
'urls' => [
'https://www.baidu.com',
'https://www.jd.com',
'...'
]
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
curl_close($ch);
$array = json_decode($output,true);
print_r($array);
Python
单页接口
import requests
url = "https://url2pic.php127.com/api/url2pic"
payload = {
'key': '您的key',
'width': 1440,
'type': 'png',
'url': 'https://www.baidu.com'
}
headers= {}
response = requests.request("POST", url, headers=headers, data = payload )
res = eval(response.text.encode('utf8'))
print(res['data'])
批量接口
import requests
url = "https://url2pic.php127.com/api/url2pic/batch"
payload = {
'key': '您的key',
'width': 1440,
'type': 'png',
'urls': ['https://www.baidu.com','https://www.jd.com']
}
headers= {}
response = requests.request("POST", url, headers=headers, data = payload )
res = eval(response.text.encode('utf8'))
print(res['data'])
NodeJs
单页接口
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://url2pic.php127.com/api/url2pic',
'headers': {
},
formData: {
'key': '您的key',
'width': 1440,
'type': 'png',
'url': 'https://www.baidu.com'
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
批量接口
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://url2pic.php127.com/api/url2pic/batch',
'headers': {
},
formData: {
'key': '您的key',
'width': 1440,
'type': 'png',
'urls': ['https://www.baidu.com','https://www.jd.com']
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
Java
单页接口
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("key", "您的key")
.addFormDataPart("url", "https://www.baidu.com")
.addFormDataPart("width", 1440)
.addFormDataPart("type", "png")
.build();
Request request = new Request.Builder()
.api_url("https://url2pic.php127.com/api/url2pic")
.method("POST", body)
.build();
Response response = client.newCall(request).execute();
批量接口
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("key", "您的key")
.addFormDataPart("urls[]", "https://www.baidu.com")
.addFormDataPart("urls[]", "https://www.jd.com")
.addFormDataPart("width", 1440)
.addFormDataPart("type", "png")
.build();
Request request = new Request.Builder()
.api_url("https://url2pic.php127.com/api/url2pic/batch")
.method("POST", body)
.build();
Response response = client.newCall(request).execute();