Last active
August 29, 2015 13:57
-
-
Save chen206/9802390 to your computer and use it in GitHub Desktop.
subscribe_api_test
This file contains hidden or 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
<? | |
$url = 'http://xx.xx.xx/xx/xx.json' //API地址,见文档 | |
$token = "xxxxxxxx"; //常量,见文档 | |
$code = "xxxxx"; //常量,见文档 | |
$name = "张三"; //用户填写的姓名 | |
$tel = "13012345678"; //用户填写的手机号 | |
$tmpArr = array($code, $token, $name, $tel); | |
sort($tmpArr, SORT_STRING); | |
$tmpStr = implode( $tmpArr ); | |
$signature = sha1( $tmpStr ); | |
$json_data = json_encode(array( | |
"code" => $code, | |
"name" => $name, | |
"tel" => $tel, | |
"signature" => $signature | |
)); | |
echo $json_data."\n"; | |
$context = stream_context_create(array( | |
'http' => array( | |
'protocol_version' => 1.1, | |
'user_agent' => '8photo', | |
'method' => 'POST', | |
'header' => "Content-type: application/json\r\n". | |
"Connection: close\r\n" . | |
"Content-length: " . strlen($json_data) . "\r\n", | |
'content' => $json_data, | |
), | |
)); | |
$post = file_get_contents($url,null,$context); | |
if ($post) { | |
echo $post; | |
} else { | |
echo "POST failed"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment