登录校验
<pre><code class="language-php">&lt;?php
/**
*
* CP校验用户有效性DEMO
*
*/
$data['user_token'] = 'rkmi2huqu9dv6750g5os11ilv2'; //获取的user_token
$data['mem_id'] = '23'; //获取的用户ID
$data['app_id'] = '1'; //获取的游戏APPID
{
//获取app_key
$appkey = 'de933fdbede098c62cb309443c3cf222'; //获取的游戏APPKEY
}
$signstr = &quot;app_id=&quot;.$data['app_id'].&quot;&amp;mem_id=&quot;.$data['mem_id'].&quot;&amp;user_token=&quot;.$data['user_token'].&quot;&amp;app_key=&quot;.$appkey;
$data['sign'] = md5($signstr);
$params = json_encode($data);
$url = &quot;http://www.***.com/sdk3.0/checkUsertoken.php&quot;; //登录校验地址(找运营获取域名地址)
$rdata = http_post_data($url, $params);
if($rdata){
$rdata = (array)json_decode($rdata);
if('1' == $rdata['status']){
//CP操作,请求成功,用户有效
echo $rdata['data'];
}
}
//HTTP json数据请求函数
function http_post_data($url, $data_string) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 3);//设置等待时间
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' . strlen($data_string))
);
ob_start();
curl_exec($ch);
$return_content = ob_get_contents();
ob_end_clean();
return $return_content;
}
</code></pre>