//芯烨云官方接口开发文档 https://www.xpyun.net/open/index.html
header("Content-type:text/html;charset=utf-8");//必须 官方要求
header("Access-Control-Allow-Origin: *");//必须 否则可能报跨域错误
$user = '*******';//芯烨云平台注册用户名(开发者 ID)
$timestamp = time();//当前UNIX时间戳,10位,精确到秒
$user_key = '023468********23110497';//用户开发者密钥
$sign = sha1($user.$user_key.$timestamp);//对参数 user + user_key + timestamp 拼接后(+号表示连接符)进行SHA1加密得到签名,值为40位小写字符串
$sn = '029*****8B49';//打印机编号
$content = '123';//打印内容
$data = json_encode(array("user"=>$user,"timestamp"=>$timestamp,"sign"=>$sign,"sn"=>$sn,"content"=>$content));
$url = "https://platform.xpyun.net/api/openapi/xprinter/print";
$result = curl_post($url,$data);
var_dump($result);
//php 模拟post请求接口
function curl_post($url,$data){
$header = array('Content-Type: application/json; charset=utf-8');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
?>