2024-12-04 12:33:47 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\robot\controller;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use app\channel\service\ChannelService;
|
|
|
|
|
use app\channel\service\ProductService;
|
|
|
|
|
use app\gateway\service\CurlService;
|
2025-01-08 22:47:33 +08:00
|
|
|
|
use app\gateway\service\RedisService;
|
2024-12-04 12:33:47 +08:00
|
|
|
|
use app\kami\service\LockCardService;
|
|
|
|
|
use app\merchant\service\MerchantService;
|
|
|
|
|
use app\merchant\service\OrderHistoryService;
|
|
|
|
|
use app\merchant\service\OrderLastHistoryService;
|
|
|
|
|
use app\merchant\service\OrderService;
|
|
|
|
|
use app\merchant\service\OrderTwoHistoryService;
|
|
|
|
|
use app\openapi\controller\Coretb;
|
|
|
|
|
use app\order\service\AfterSalesOrderService;
|
|
|
|
|
use app\robot\controller\api\Qqbot;
|
|
|
|
|
use think\admin\Controller;
|
|
|
|
|
use think\exception\HttpResponseException;
|
|
|
|
|
use think\facade\Db;
|
|
|
|
|
use think\facade\Log;
|
|
|
|
|
|
|
|
|
|
//use app\merchant\service\OrderLastweekHistoryService;
|
|
|
|
|
|
|
|
|
|
#微信机器人 #
|
|
|
|
|
class WeChatBot extends Controller
|
|
|
|
|
{
|
|
|
|
|
protected array $status_map=array(
|
|
|
|
|
-1=>'暂无订单',
|
|
|
|
|
-2=>'暂无卡密',
|
|
|
|
|
1=>'成功'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
protected string $host = 'http://111.229.68.136:9999/';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function initialize(): void
|
|
|
|
|
{
|
|
|
|
|
#47609e509f946ecbfdba27f16db341c4
|
|
|
|
|
|
|
|
|
|
parent::initialize();
|
|
|
|
|
|
|
|
|
|
#获取wechat信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#发送文本
|
|
|
|
|
public function send_text($content,$receiver,$aters =false)
|
|
|
|
|
{
|
|
|
|
|
$url = $this->host.'text';
|
|
|
|
|
$request = [
|
|
|
|
|
'aters' =>'',
|
|
|
|
|
'msg'=>$content,
|
|
|
|
|
'receiver'=>$receiver
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if($aters){
|
|
|
|
|
$request['aters'] = $aters;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-15 19:00:17 +08:00
|
|
|
|
|
2024-12-04 12:33:47 +08:00
|
|
|
|
return $this->curl('post', $url,$request,true);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function get_all_contacts()
|
|
|
|
|
{
|
|
|
|
|
$url = $this->host.'contacts';
|
|
|
|
|
|
|
|
|
|
return $this->curl('get', $url);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-08 22:47:33 +08:00
|
|
|
|
public function send_image($content,$receiver,$aters =false)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function get_contacts($wx_id)
|
|
|
|
|
{
|
|
|
|
|
$redis = RedisService::getInstance();
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
|
|
$data = $redis->get('Wechat_all_contacts');
|
|
|
|
|
if($data){
|
|
|
|
|
foreach ($data as $k=>$v){
|
|
|
|
|
if($v['wxid'] == $wx_id){
|
|
|
|
|
return $v['name'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$all_contacts = $this->get_all_contacts();
|
|
|
|
|
$Contacts_array = json_decode($all_contacts,true);
|
|
|
|
|
if(!is_array($Contacts_array) || !isset( $Contacts_array['data']['contacts']) )return false;
|
|
|
|
|
|
|
|
|
|
$acc = $Contacts_array['data']['contacts'];
|
|
|
|
|
foreach ($acc as $k=>$v){
|
|
|
|
|
if($v['wxid'] == $wx_id){
|
|
|
|
|
$redis->delete('Wechat_all_contacts');
|
2025-02-15 19:00:17 +08:00
|
|
|
|
$redis->set('Wechat_all_contacts',$Contacts_array['data']['contacts'],86400);
|
2025-01-08 22:47:33 +08:00
|
|
|
|
return $v['name'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
$all_contacts = $this->get_all_contacts();
|
|
|
|
|
$Contacts_array = json_decode($all_contacts,true);
|
|
|
|
|
if(!is_array($Contacts_array) || !isset( $Contacts_array['data']['contacts']) )return false;
|
|
|
|
|
|
|
|
|
|
$acc = $Contacts_array['data']['contacts'];
|
|
|
|
|
foreach ($acc as $k=>$v){
|
|
|
|
|
if($v['wxid'] == $wx_id){
|
2025-02-15 19:00:17 +08:00
|
|
|
|
$redis->set('Wechat_all_contacts',$Contacts_array['data']['contacts'],86400);
|
2025-01-08 22:47:33 +08:00
|
|
|
|
return $v['name'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}catch (\Exception $e){
|
|
|
|
|
try{
|
|
|
|
|
$all_contacts = $this->get_all_contacts();
|
|
|
|
|
$Contacts_array = json_decode($all_contacts,true);
|
|
|
|
|
if(!is_array($Contacts_array) || !isset( $Contacts_array['data']['contacts']) )return false;
|
|
|
|
|
|
|
|
|
|
$acc = $Contacts_array['data']['contacts'];
|
|
|
|
|
foreach ($acc as $k=>$v){
|
|
|
|
|
if($v['wxid'] == $wx_id){
|
|
|
|
|
return $v['name'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}catch (\Exception $e){
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-04 12:33:47 +08:00
|
|
|
|
|
2025-02-15 19:00:17 +08:00
|
|
|
|
public function set_manage($wx_id,$type = 1)
|
|
|
|
|
{
|
|
|
|
|
$redis = RedisService::getInstance();
|
|
|
|
|
$name = $this->get_contacts($wx_id);
|
|
|
|
|
|
|
|
|
|
if($name){
|
|
|
|
|
$get = $redis->get('Wechat_manage_' . $wx_id);
|
|
|
|
|
if($type == 1) {
|
|
|
|
|
|
|
|
|
|
if($get){
|
|
|
|
|
if($get != $name){
|
|
|
|
|
$redis->set('Wechat_manage_' . $wx_id, $name);
|
|
|
|
|
}
|
|
|
|
|
return '已经设置过管理员';
|
|
|
|
|
}
|
|
|
|
|
$redis->set('Wechat_manage_' . $wx_id, $name);
|
|
|
|
|
return 'ok';
|
|
|
|
|
}
|
|
|
|
|
if($type == 2) {
|
|
|
|
|
if(!$get){
|
|
|
|
|
return '不存在管理员';
|
|
|
|
|
}
|
|
|
|
|
$redis->delete('Wechat_manage_' . $wx_id);
|
|
|
|
|
return 'ok';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 'fail';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-12-04 12:33:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 是否检测数据
|
|
|
|
|
// protected bool $check = false;
|
|
|
|
|
|
|
|
|
|
# 查询接口 一般用于查询数据,同步执行
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 提交接口 一般用于提交数据,异步执行
|
|
|
|
|
|
|
|
|
|
public function send($url, $param)
|
|
|
|
|
{
|
|
|
|
|
$geturl = 'http://127.0.0.1:7374/' . $url;
|
|
|
|
|
|
|
|
|
|
return http_post($geturl, $param);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function send_post($notify_url, $post_data, $type): mixed
|
|
|
|
|
{
|
|
|
|
|
$postdate = json_encode($post_data);
|
|
|
|
|
|
|
|
|
|
// $postdate = http_build_query($post_data);
|
|
|
|
|
|
|
|
|
|
$options = array(
|
|
|
|
|
'http' => array(
|
|
|
|
|
'method' => $type,
|
|
|
|
|
'header' => 'Content-type:application/json',
|
|
|
|
|
'content' => $postdate,
|
|
|
|
|
'timeout' => 15 * 60 // 超时时间(单位:s)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
$context = stream_context_create($options);
|
|
|
|
|
return file_get_contents($notify_url, false, $context);
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-15 19:02:39 +08:00
|
|
|
|
public function curl($method, $url, $param = array(), $json = false, $header = false):mixed
|
2024-12-04 12:33:47 +08:00
|
|
|
|
{
|
|
|
|
|
if ($param) {
|
|
|
|
|
$log['type'] = 'request';
|
|
|
|
|
$log['url'] = $url;
|
|
|
|
|
$log['param'] = $param;
|
|
|
|
|
$this->log($log);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$curl = CurlService::getInstance($url, $param, $method, $json, $header);
|
|
|
|
|
$curl->setTimeOut(3600);
|
|
|
|
|
return $curl->result();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static function log($data, $type = 'request'):void
|
|
|
|
|
{
|
|
|
|
|
\dever\Log::write('kami91', $type, $data);
|
|
|
|
|
// \dever\Log::write('jingdong', $type, $data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|