<?php
//获取POS收银系统AccessToken by benson
function getAccessToken($shopid,$password){
$arr = array(
'shopid'=>$shopid,
'password'=>$password
);
$data_string = json_encode($arr);
//json也可以
//普通数组也行
//$data_string = $arr;
//echo '<br>';
//curl验证成功
$ch = curl_init("https://open.kiwisoft.cn/cgi-bin/shop/get_key");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string)
));
$result = curl_exec($ch);
if (curl_errno($ch)) {
print curl_error($ch);
}
curl_close($ch);
$result1 = json_decode($result, true); //接受一个 JSON 格式的字符串并且把它转换为 PHP 变
$access_token = $result1['access_token'];
return $access_token;
}
?
引用文字