329 lines
8.7 KiB
PHP
329 lines
8.7 KiB
PHP
<?php
|
|
|
|
namespace app\kami\controller\suoka;
|
|
|
|
|
|
use app\kami\controller\getcookie\Whymcl as WhymclCookie;
|
|
use dever\Log;
|
|
|
|
|
|
#中兆
|
|
|
|
class Whymcl extends Core
|
|
{
|
|
# 登录获取
|
|
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'];
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
#获取锁卡id
|
|
|
|
public function get_suoka_id($url,$cookie_path,$cardno,$type= 1){
|
|
$postData = [
|
|
'page'=>1,
|
|
'card' => $cardno
|
|
|
|
|
|
];
|
|
|
|
|
|
$headers = array(
|
|
'X-Requested-With: XMLHttpRequest',
|
|
|
|
);
|
|
|
|
$options['cookie_file'] = $cookie_path;
|
|
$options['headers'] = $headers;
|
|
|
|
$result = http_get( $url, $postData, $options);
|
|
$response = json_decode($result, true);
|
|
// var_dump($response);die;
|
|
if(isset($response['code'])&&$response['code'] ==0 && isset($response['data']['total'] )){
|
|
if($response['data']['total'] ==1){
|
|
return $response['data']['data'][0];
|
|
}elseif($response['data']['total'] ==0){
|
|
return "未找到可用锁卡id";
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* php截取指定两个字符之间字符串方式二
|
|
* @param string $str 需要截取的字符串
|
|
* @param string $start 开始字符串
|
|
* @param string $end 结束字符串
|
|
* @return string
|
|
*/
|
|
public function get_between($str, $start, $end) {
|
|
$substr = substr($str, strlen($start)+strpos($str, $start),(strlen($str) - strpos($str, $end))*(-1));
|
|
return $substr;
|
|
}
|
|
|
|
public function UnlockCard($cid,$cardno,$cardpwd,$pid,$cash,$num = 0)
|
|
{
|
|
$suokaRequest = $this->getChanelSuoKaData($cid);
|
|
|
|
if(!$suokaRequest == 'error'){
|
|
return 'error';
|
|
}
|
|
if(isset($suokaRequest['card_kind_'.$cid.'00'.$pid])){
|
|
$card_kind = $suokaRequest['card_kind_'.$cid.'00'.$pid];
|
|
}else{
|
|
return 'error';
|
|
}
|
|
|
|
|
|
$url = $suokaRequest['un_suoka_url'];
|
|
|
|
$cookie_path = $this->getcCookiePatch($cid);
|
|
|
|
|
|
$cookie_path .= 'cookie.txt';
|
|
|
|
|
|
if (is_readable($cookie_path)) {
|
|
$cookies = file_get_contents($cookie_path);
|
|
|
|
|
|
// 处理文件内容
|
|
} else {
|
|
|
|
// 文件不存在或不可读
|
|
$WhymclCookie = new WhymclCookie($this->app);
|
|
$request = [
|
|
'login_info' => [
|
|
'username' => $suokaRequest['username'],
|
|
'password' => $suokaRequest['password'],
|
|
],
|
|
'login_url' => $suokaRequest['login_url'],
|
|
'cid' => $cid
|
|
];
|
|
$cookie_path = $WhymclCookie->login($request);
|
|
if($cookie_path == 'error'){
|
|
return $cookie_path;
|
|
}else{
|
|
$cookies = file_get_contents($cookie_path);
|
|
}
|
|
}
|
|
// var_dump($cookies);
|
|
|
|
|
|
|
|
$suoka_id_array = $this->get_suoka_id($suokaRequest['suokaid_url'], $cookie_path, $cardno);
|
|
//
|
|
if(!$suoka_id_array){
|
|
unlink($cookie_path);
|
|
if($num == 0){
|
|
$this->UnlockCard($cid, $cardno, $cardpwd, $pid, $cash,1);
|
|
}
|
|
return 'error';
|
|
}
|
|
|
|
if(is_array($suoka_id_array)) {
|
|
|
|
if($suoka_id_array['is_lock'] == 0){
|
|
return 'ok';
|
|
}
|
|
|
|
#http://taobao.whymcl.cn/tb.php/taobao/lock.html
|
|
|
|
|
|
$headers = array(
|
|
'X-Requested-With: XMLHttpRequest',
|
|
);
|
|
$options['cookie_file'] = $cookie_path;
|
|
$options['headers'] = $headers;
|
|
$postData = [
|
|
'id' => $suoka_id_array['id'],
|
|
];
|
|
|
|
|
|
$result = http_post($url, $postData, $options);
|
|
// var_dump($result);die;
|
|
if (str_contains($result, '操作成功')) {
|
|
$suoka_id_msg = $this->get_suoka_id($suokaRequest['suokaid_url'], $cookie_path, $cardno);
|
|
if (!$suoka_id_msg) {
|
|
unlink($cookie_path);
|
|
if ($num == 0) {
|
|
$this->UnlockCard($cid, $cardno, $cardpwd, $pid, $cash, 1);
|
|
}
|
|
return 'error';
|
|
}
|
|
|
|
if (is_array($suoka_id_msg)) {
|
|
if ($suoka_id_msg['is_lock'] == 0) {
|
|
return 'ok';
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
return 'error';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function suoka($cid,$cardno,$cardpwd,$pid,$cash,$num = 0)
|
|
{
|
|
$suokaRequest = $this->getChanelSuoKaData($cid);
|
|
|
|
if(!$suokaRequest == 'error'){
|
|
return 'error';
|
|
}
|
|
if(isset($suokaRequest['card_kind_'.$cid.'00'.$pid])){
|
|
$card_kind = $suokaRequest['card_kind_'.$cid.'00'.$pid];
|
|
}else{
|
|
return 'error';
|
|
}
|
|
|
|
|
|
$url = $suokaRequest['suoka_url'];
|
|
|
|
$cookie_path = $this->getcCookiePatch($cid);
|
|
|
|
|
|
$cookie_path .= 'cookie.txt';
|
|
|
|
|
|
if (is_readable($cookie_path)) {
|
|
$cookies = file_get_contents($cookie_path);
|
|
|
|
|
|
// 处理文件内容
|
|
} else {
|
|
|
|
// 文件不存在或不可读
|
|
$WhymclCookie = new WhymclCookie($this->app);
|
|
$request = [
|
|
'login_info' => [
|
|
'username' => $suokaRequest['username'],
|
|
'password' => $suokaRequest['password'],
|
|
],
|
|
'login_url' => $suokaRequest['login_url'],
|
|
'cid' => $cid
|
|
];
|
|
$cookie_path = $WhymclCookie->login($request);
|
|
if($cookie_path == 'error'){
|
|
return $cookie_path;
|
|
}else{
|
|
$cookies = file_get_contents($cookie_path);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$suoka_id_array = $this->get_suoka_id($suokaRequest['suokaid_url'], $cookie_path, $cardno);
|
|
// var_dump($suoka_id_array);die;
|
|
if(!$suoka_id_array){
|
|
unlink($cookie_path);
|
|
if($num == 0){
|
|
$this->suoka($cid, $cardno, $cardpwd, $pid, $cash,1);
|
|
}
|
|
return 'error';
|
|
}
|
|
|
|
if(is_array($suoka_id_array)) {
|
|
if($suoka_id_array['is_lock'] == 1){
|
|
return 'old_ok';
|
|
}
|
|
|
|
#http://taobao.whymcl.cn/tb.php/taobao/lock.html
|
|
|
|
|
|
$headers = array(
|
|
'X-Requested-With: XMLHttpRequest',
|
|
);
|
|
$options['cookie_file'] = $cookie_path;
|
|
$options['headers'] = $headers;
|
|
$postData = [
|
|
'id' => $suoka_id_array['id'],
|
|
];
|
|
|
|
$result = http_post($suokaRequest['get_suoka_url'], $postData, $options);
|
|
if (str_contains($result, '操作成功')) {
|
|
$suoka_id_msg = $this->get_suoka_id($suokaRequest['suokaid_url'], $cookie_path, $cardno);
|
|
if (!$suoka_id_msg) {
|
|
unlink($cookie_path);
|
|
if ($num == 0) {
|
|
$this->suoka($cid, $cardno, $cardpwd, $pid, $cash, 1);
|
|
}
|
|
return 'error';
|
|
}
|
|
|
|
if (is_array($suoka_id_msg)) {
|
|
if ($suoka_id_msg['is_lock'] == 1) {
|
|
return 'ok';
|
|
}
|
|
}
|
|
|
|
}
|
|
}else{
|
|
$headers = array(
|
|
'X-Requested-With: XMLHttpRequest',
|
|
'Content-Type: application/x-www-form-urlencoded',
|
|
'Accept: */*',
|
|
'Connection: keep-alive',
|
|
);
|
|
$options['cookie_file'] = $cookie_path;
|
|
$options['headers'] = $headers;
|
|
|
|
|
|
$postData = [
|
|
'card_no' => $cardno,
|
|
'card_key'=>$cardpwd,
|
|
'sole'=>$card_kind,
|
|
];
|
|
$result = http_post($url, $postData, $options);
|
|
$array =json_decode($result,true);
|
|
if(!is_array($array)){
|
|
unlink($cookie_path);
|
|
if ($num == 0) {
|
|
$this->suoka($cid, $cardno, $cardpwd, $pid, $cash, 1);
|
|
}
|
|
return 'error';
|
|
}
|
|
if (str_contains($result, '添加成功')) {
|
|
return 'ok';
|
|
|
|
}else{
|
|
Log::write('kami', 'Whymcl', $cardno);
|
|
return 'error';
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} |