Created
August 23, 2017 14:57
-
-
Save fhefh2015/09970bfbcee0e3aa4d83584024b49f40 to your computer and use it in GitHub Desktop.
simimg.com图片上传
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by PhpStorm. | |
*/ | |
//composer require mashape/unirest-php | |
include_once __DIR__ . '/vendor/autoload.php'; | |
function uploadMyPic($file_path) | |
{ | |
$url='https://simimg.com/'; | |
$upload_url='https://simimg.com/json'; | |
//获取页面cookies | |
$response = Unirest\Request::post($url); | |
$tmp_cookie = explode(';', $response->headers['Set-Cookie']); | |
$cookie = $tmp_cookie[0]; | |
//获取token | |
$body = $response->raw_body; | |
preg_match_all('/PF.obj.config.auth_token\s+=\s+\"(.*)\"/', $body, $match); | |
$authon_token = $match[1][0]; | |
//上传图片 | |
$headers = array('Accept' => 'application/json', 'Cookie' => $cookie, 'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36'); | |
$body = array( | |
"type" => "file", | |
"action" => "upload", | |
"nsfw" => "0", | |
'auth_token' => $authon_token, | |
'source' => Unirest\Request\Body::file($file_path, 'image/jpeg') | |
); | |
$response = Unirest\Request::post($upload_url, $headers, $body); | |
return $response; | |
} | |
var_dump(uploadMyPic('./wx2.jpg')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment