147 lines
3.7 KiB
PHP
147 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace app\kami\controller\suoka;
|
|
|
|
//use app\kami\get\api\Coreks;
|
|
//use app\gateway\service\RedisService;
|
|
//use think\exception\HttpResponseException;
|
|
|
|
//use app\kami\getcookie\Controller;
|
|
use app\kami\controller\getcookie\Shengxiakami as KaiDianBaoCookie;
|
|
|
|
use dever\Log;
|
|
use think\admin\Controller;
|
|
|
|
class Shengxiakami extends Core
|
|
{
|
|
# 登录获取
|
|
public function suoka($cid,$cardno,$cardpwd,$pid,$cash,$num = 0)
|
|
{
|
|
|
|
|
|
$suokaRequest = $this->getChanelSuoKaData($cid);
|
|
if(!$suokaRequest == 'error'){
|
|
return 'error';
|
|
}
|
|
|
|
$url = $suokaRequest['suoka_url'];
|
|
|
|
$cookie_path = $this->getcCookiePatch($cid);
|
|
// /www/sites/reapi/index/extend/data/cookie/5//cookie.txt
|
|
|
|
$cookie_path .= 'cookie.txt';
|
|
// $cookies = file_get_contents($cookie_path);
|
|
// var_dump($cookies);die;
|
|
|
|
if (is_readable($cookie_path)) {
|
|
$cookies = file_get_contents($cookie_path);
|
|
|
|
|
|
// 处理文件内容
|
|
} else {
|
|
|
|
// 文件不存在或不可读
|
|
$KaiDianBaoCookie = new KaiDianBaoCookie($this->app);
|
|
$request = [
|
|
'login_info' => [
|
|
'username' => $suokaRequest['username'],
|
|
'password' => $suokaRequest['password']
|
|
],
|
|
'login_url' => $suokaRequest['login_url'],
|
|
'cid' => $cid
|
|
];
|
|
$cookie_path = $KaiDianBaoCookie->login($request);
|
|
// Log::write('suoka', 'kaidianbao', $cookie_path);
|
|
if($cookie_path == 'error'){
|
|
return $cookie_path;
|
|
}else{
|
|
$cookies = file_get_contents($cookie_path);
|
|
}
|
|
}
|
|
|
|
$card_kind = $this->get_card_kind($pid, $cash);
|
|
|
|
|
|
$ch = curl_init(); // 创建cURL资源对象
|
|
|
|
$postData = [
|
|
'cardNo' => $cardno,
|
|
'cardPwd' => $cardpwd,
|
|
'card_kind' => $card_kind,
|
|
'cardFace' => $cash,
|
|
'lockType' => '1'
|
|
|
|
];
|
|
// var_dump($postData);die;
|
|
$options['cookie_file'] = $cookie_path;
|
|
|
|
$result = http_post( $url, $postData, $options);
|
|
// var_dump($result);die;
|
|
Log::write('suoka', 'kaidianbao', $result);
|
|
|
|
|
|
$result = json_decode($result,true);
|
|
|
|
//
|
|
|
|
|
|
if(isset($result['msg']) && $result['msg'] == '锁卡成功'){
|
|
|
|
return 'ok';
|
|
}elseif(isset($result['msg']) && $result['msg'] == '登录失败,参数错误'){
|
|
if (is_readable($cookie_path)) {
|
|
unlink($cookie_path);
|
|
|
|
|
|
// 处理文件内容
|
|
}
|
|
|
|
if($num <= 2){
|
|
$num++;
|
|
return $this->suoka($cid, $cardno, $cardpwd, $pid, $cash,$num);
|
|
|
|
|
|
|
|
}else{
|
|
return 'error';
|
|
}
|
|
|
|
}else{
|
|
if (is_readable($cookie_path)) {
|
|
unlink($cookie_path);
|
|
// 处理文件内容
|
|
}
|
|
if($num <= 2){
|
|
$num++;
|
|
return $this->suoka($cid, $cardno, $cardpwd, $pid, $cash,$num);
|
|
|
|
|
|
}else{
|
|
Log::write('kami', 'kaidianbao', $result);
|
|
return 'error';
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public function get_card_kind($pid,$cash)
|
|
{
|
|
$info = $this->getProductInfo($pid);
|
|
if ($info) {
|
|
if (isset($info['gid_rule']) && $info['gid_rule']) {
|
|
$rule = json_decode($info['gid_rule'], true);
|
|
if (isset($rule[$cash]) && $rule[$cash]) {
|
|
$gid = $rule[$cash];
|
|
return $gid;
|
|
}
|
|
}
|
|
if (isset($info['gid']) && $info['gid']) {
|
|
return $info['gid'];
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
} |