wugg 7 meses atrás
pai
commit
aa9cf48541

+ 9 - 2
app/bug/controller/Note.php

@@ -203,7 +203,8 @@ class Note extends Base
     }
 
     public function wxpushList(){
-	    $param = $this->request->param(["start"=>"","end"=>"","bugNo"=>"","push_id"=>"","template_name"=>"","template_id"=>"","status"=>"",
+	    $param = $this->request->param(["start"=>"","end"=>"","bugNo"=>"","push_id"=>"","template_name"=>"",
+	    "template_id"=>"","status"=>"",'belong'=>'','action_name'=>'',
 	    "page"=>1,"size"=>10],'post','trim');
 	    $where=[];
 	    if($param['start']!==""){
@@ -227,7 +228,13 @@ class Note extends Base
 	    if($param['status']!==""){
 	        $where[]=['status',"=",$param['status']];
 	    }
-	    $list = \app\bug\model\WechatPush::with(['note'])->where($where)->order("createTime desc")->paginate(["list_rows"=>$param['size'],"page"=>$param['page']]);
+	    if($param['belong']!==""){
+	        $where[]=['belong',"=",$param['belong']];
+	    }
+	    if($param['action_name']!==""){
+	        $where[]=['action_name',"like","%{$param['action_name']}%"];
+	    }
+	    $list = \app\bug\model\WechatPush::where($where)->order("createTime desc")->paginate(["list_rows"=>$param['size'],"page"=>$param['page']]);
 	    return success("获取成功",['list'=>$list->items(),'count'=>$list->total()]);
     }
 }

+ 3 - 2
app/bug/controller/Role.php

@@ -2,8 +2,9 @@
 
 
 namespace app\bug\controller;
-use app\bug\model\RoleAction;use think\App;
-use think\facade\Db;use think\facade\Validate;
+use app\bug\model\RoleAction;
+use think\App;
+use think\facade\Validate;
 class Role extends Base
 {
 	protected $noLogin=[];

+ 24 - 41
app/bug/listener/WxPush.php

@@ -5,7 +5,7 @@ namespace app\bug\listener;
 
 use app\bug\model\Note;
 use app\bug\model\Talk;use app\user\model\User;
-use think\facade\Log;
+use think\facade\Cache;use think\facade\Log;
 class WxPush
 {
     protected $appid;
@@ -32,7 +32,6 @@ class WxPush
         }
         $data = $event['data'];
         $this->uid = Talk::$talkUid;
-
         try {
             switch ($event['type']) {
                 case 'bug':
@@ -128,50 +127,34 @@ class WxPush
                 ];
                 break;
         }
-        $add=[];
         foreach ($openidArr as $item){
-          if(empty($item['openId'])){
-              $add[]=[
-                'bugNo'=>$data['bugNo'],
-                'template_id'=>$template_id,
-                'template_name'=>$template_name,
-                'content'=>json_encode($temp,JSON_UNESCAPED_UNICODE),
-                'push_id'=>$item['account_id'],
-                'pusher'=>$item['nickname'],
-                'status'=>0,
-                'remark'=>"openId 不存在"
-            ];
-              continue;
-          };
-          $res=$this->pushMessage($item['openId'],$template_id,$temp);
-          $add[]=[
-                "bugNo"=>$data['bugNo'],
+          $temps=[
+                "code"=>$data['bugNo'],
+                "belong"=>4,
+                "openId"=>$item['openId'],
                 "template_id"=>$template_id,
                 "template_name"=>$template_name,
-                "content"=>json_encode($temp,JSON_UNESCAPED_UNICODE),
-                "push_id"=>$item['account_id'],
-                "pusher"=>$item['nickname'],
-                "status"=>$res?1:0,
-                "remark"=>$res?"":$this->wechat->errMsg
+                "action_name"=>'工单推送',
+                "template_data"=>$temp,
+                "uid"=>$item['account_id'],
+                "uname"=>$item['nickname'],
             ];
-        }
-        if(!empty($add)){
-            (new \app\bug\model\WechatPush)->saveAll($add);
+          Cache::store('redis')->handler()->lpush('wxpush_queue',json_encode($temps,JSON_UNESCAPED_UNICODE));
         }
     }
 
-    public function pushMessage($openId,$template_id,$data){
-            $temp=[];
-            $temp['touser'] =$openId;
-            $temp['template_id'] = $template_id;
-            $temp['data']=$data;
-            $res= $this->wechat->sendTemplateMessage($temp);
-            if($res==false && $this->wechat->errCode==40001){
-                $this->wechat->resetAuth(env("WECHAT.APPID"));
-                $this->wechat->sendTemplateMessage($temp);
-            }
-            Log::write('data:'.json_encode($temp,JSON_UNESCAPED_UNICODE),'event');
-            Log::write('data:'.json_encode($res,JSON_UNESCAPED_UNICODE),'event');
-            return $res;
-    }
+//    public function pushMessage($openId,$template_id,$data){
+//            $temp=[];
+//            $temp['touser'] =$openId;
+//            $temp['template_id'] = $template_id;
+//            $temp['data']=$data;
+//            $res= $this->wechat->sendTemplateMessage($temp);
+//            if($res==false && $this->wechat->errCode==40001){
+//                $this->wechat->resetAuth(env("WECHAT.APPID"));
+//                $this->wechat->sendTemplateMessage($temp);
+//            }
+//            Log::write('data:'.json_encode($temp,JSON_UNESCAPED_UNICODE),'event');
+//            Log::write('data:'.json_encode($res,JSON_UNESCAPED_UNICODE),'event');
+//            return $res;
+//    }
 }

+ 1 - 1
app/bug/model/WechatPush.php

@@ -7,6 +7,6 @@ namespace app\bug\model;
 class WechatPush extends Base {
     protected $createTime='createTime';
     public function Note(){
-        return $this->belongsTo('Note','bugNo','bugNo')->bind(['title']);
+        return $this->belongsTo('Note','bugNo','bugNo')->where('belong',4)->bind(['title']);
     }
 }

+ 64 - 0
app/command/WxPush.php

@@ -0,0 +1,64 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\command;
+
+use app\bug\model\WechatPush;use think\console\Command;
+use think\console\Input;
+use think\console\input\Argument;
+use think\console\input\Option;
+use think\console\Output;use think\facade\Cache;use think\facade\Log;
+
+class WxPush extends Command
+{
+    protected function configure()
+    {
+        // 指令配置
+        $this->setName('wxpush')
+            ->setDescription('the wxpush command');
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+        $appid = env('WECHAT.APPID');
+        $appsecret = env('WECHAT.APPSECRET');
+        $wechat = new \Wechat(['appid' => $appid, 'appsecret' => $appsecret]);
+       $bool=True;
+       while ($bool){
+            $que= Cache::store('redis')->handler()->lpop('wxpush_queue');
+            if ($que){
+                $data=json_decode($que,true);
+                $temp=[];
+                $res=false;
+                if($data['openId']!=''){
+                    $temp['touser'] =$data['openId'];
+                    $temp['template_id'] = $data['template_id'];
+                    $temp['data']=$data['template_data'];
+                    $res= $wechat->sendTemplateMessage($temp);
+                    if($res==false && $wechat->errCode==40001){
+                        $wechat->resetAuth(env('WECHAT.APPID'));
+                        $wechat->sendTemplateMessage($temp);
+                    }
+                }
+
+                $add= [
+                    'bugNo'=>$data['code'],
+                    "belong"=>$data['belong'],
+                    'action_name'=>$data['action_name'],
+                    'template_id'=>$data['template_id'],
+                    'template_name'=>$data['template_name'],
+                    'content'=>json_encode($temp,JSON_UNESCAPED_UNICODE),
+                    'push_id'=>$data['uid'],
+                    'pusher'=>$data['uname'],
+                    'status'=>$res?1:0,
+                    'remark'=>$res?'':$wechat->errMsg
+                    ];
+                 WeChatPush::create($add);
+                Log::write('data:'.json_encode($temp,JSON_UNESCAPED_UNICODE),'info');
+            }else{
+                $bool=false;
+            }
+       }
+
+    }
+}

+ 12 - 11
app/common/Ocr.php

@@ -74,9 +74,10 @@ class Ocr {
     * code  发票代码。发票种类为全电发票时,该参数须为空字符串。
     * number  发票号码
     * issueDate  发票日期格式YYYY-MM-DD
-    * checkCode  校验码后六位。 - 以下种类发票,参数不可为空    增值税普通发票、增值税电子普通发票、增值税普通发票(卷式)、增值税电子普通发票(通行费)、区块链电子发票。  - 区块链电子发票需要填写5位校验码。
-    * subtotalAmount  合计金额。和票据上的金额的有效数字保持一致,例如票据上的金额为88.00,则需要输入字符串为“88.00”,才能验真成功。如果输入“88”或“88.0”可能会产生\"result_code\": \"1010\", \" Parameter error.\"报错。  发票种类为全电发票时,该参数须为价税合计金额,其他票种使用不含税合计金额。  - 以下种类发票,参数不可为空    增值税专用发票、增值税电子专用发票、机动车销售统一发票、二手车销售统一发票、区块链电子发票、全电发票。  - 填写发票合计金额(不含税)    增值税专用发票、增值税电子专用发票、机动车销售统一发票、区块链电子发票。  - 二手车发票需要填写发票车价合计金额
-    *
+    * checkCode  校验码后六位。 - 以下种类发票,参数不可为空    增值税普通发票、增值税电子普通发票、增值税普通发票(卷式)、增值税电子普通发票(通行费)、区块链电子发票。
+    * - 区块链电子发票需要填写5位校验码。
+    * subtotalAmount  合计金额。和票据上的金额的有效数字保持一致,例如票据上的金额为88.00,则需要输入字符串为“88.00”,才能验真成功。如果输入“88”或“88.0”可能会产生\"result_code\": \"1010\", \" Parameter error.\"报错。
+    * 发票种类为全电发票时,该参数须为价税合计金额,其他票种使用不含税合计金额。  - 以下种类发票,参数不可为空    增值税专用发票、增值税电子专用发票、机动车销售统一发票、二手车销售统一发票、区块链电子发票、全电发票。  - 填写发票合计金额(不含税)    增值税专用发票、增值税电子专用发票、机动车销售统一发票、区块链电子发票。  - 二手车发票需要填写发票车价合计金额
     * @var string[]
     */
     public static function InvoiceVerification($code='',$number='',$issueDate='',$checkCode='',$subtotalAmount='') {
@@ -86,12 +87,13 @@ class Ocr {
         $issueDate = date('Y-m-d',strtotime($issueDate));
         if($checkCode!=""&&strlen($checkCode)!=6)$checkCode=substr($checkCode,0,6);
         if($subtotalAmount!="")$subtotalAmount= number_format($subtotalAmount, 2, '.', '');
-        if($code!="")$body->setCode($code);
-        if($number!="")$body->setNumber($number);
-        if($issueDate!="")$body->setIssueDate($issueDate);
-        if($checkCode!="")$body->setCheckCode($checkCode);
-        if($subtotalAmount!="")$body->setSubtotalAmount($subtotalAmount);
-        $request->setBody($body);
+       $body->setCode($code);
+       $body->setNumber($number);
+       $body->setIssueDate($issueDate);
+       $body->setCheckCode($checkCode);
+       $body->setSubtotalAmount($subtotalAmount);
+       $request->setBody($body);
+
         $msg = '';
         try {
           $response = $client->RecognizeInvoiceVerification($request);
@@ -102,11 +104,10 @@ class Ocr {
         } catch (ServiceResponseException $e) {
           $msg = $e->getErrorMsg();
         }
-
         if ($msg) {
           return ["isResult"=>false,"msg"=>$msg];
         } else {
-          return ['isResult'=>true,'msg'=>"获取成功","data"=>json_decode($response->getResult()->__toString(),true)];
+          return ['isResult'=>true,'msg'=>"获取成功","data"=>json_decode($response,true)];
         }
 
     }

+ 2 - 1
app/user/controller/Base.php

@@ -6,7 +6,8 @@ namespace app\user\controller;
 
 use app\BaseController;
 use app\common\Ocr;
-use think\App;use think\Exception;
+use think\App;
+use think\Exception;
 class Base extends BaseController{
 	protected  $uid=0;
 	protected  $uname='system';

+ 5 - 4
app/user/model/Headquarters.php

@@ -39,10 +39,13 @@ use think\Exception;use think\Model;class Headquarters extends Base
     * @throws Exception
      */
     public static function createInfo($object,$type){
+
         $result =self::checkObject($object,$type);
         if(empty($result))throw new Exception("公司数据创建失败");
-        $isobj= self::where(['code'=>$result['code'],"is_del"=>0])->findOrEmpty();
-        if(!$isobj->isEmpty() && $type==3 && $object->is_upgrade==1)self::sycCompany($isobj->relation_code,$object);
+        $isobj= self::where(['code'=>$result['code'],'is_del'=>0])->findOrEmpty();
+        if(!$isobj->isEmpty() && $type==3 && $object->is_upgrade==1){
+            self::sycCompany($isobj->relation_code,$object);
+        }
 
         $result['id']=$isobj->isEmpty()?null:$isobj->id;
         $info = $isobj->save($result);
@@ -73,7 +76,6 @@ use think\Exception;use think\Model;class Headquarters extends Base
                     'invoice_img'       =>$object->license_img,//营业执照
                     'remark'       =>'',//备注
                     "is_del"=>$object->is_del??0,
-                    "relation_code"=>$object->relation_code??"",
                     "creater"=>$object->creater,
                     "createrid"=>$object->createrid,
                     'updater' => $object->updater,
@@ -118,7 +120,6 @@ use think\Exception;use think\Model;class Headquarters extends Base
                     'invoice_img'       =>$object->license_img??'',//营业执照
                     'remark'       =>'',//备注
                     'is_del'=>$object->is_del??0,
-                    'relation_code'=>$object->relation_code??'',
                     'creater'=>$object->creater,
                     'createrid'=>$object->createrid,
                     'updater' => $object->updater,

+ 32 - 0
app/wechat/controller/Base.php

@@ -0,0 +1,32 @@
+<?php
+namespace app\wechat\controller;
+
+use think\App;
+class Base extends \app\BaseController{
+    protected  $uid=0;
+	protected  $uname='system';
+	protected  $noLogin=[];
+	protected  $token='';
+	protected  $model=null;
+	protected  $keepTime=3600;
+    public function __construct(App $app) {
+        parent::__construct($app);
+		$this->token = $this->request->param('token','','trim');
+	    if (!action_in_arr($this->noLogin)){
+	    	if($this->token=='')throw new \Exception('token不能为空',101);
+	        $this->Auth();
+	    }
+    }
+
+     /**授权token鉴定
+	* @return \think\response\Json|void
+	 */
+   protected function Auth(){
+   	  $User = \app\common\User::instance();
+   	  $User->init($this->token);
+   	  if (!$User->isLogin()) throw new \Exception($User->getError(),$User->getErroCode());
+   	  $this->uid = $User->id;
+   	  $this->uname = $User->nickname;
+   }
+
+}

+ 76 - 0
app/wechat/controller/Wechat.php

@@ -0,0 +1,76 @@
+<?php
+
+
+namespace app\wechat\controller;
+
+
+use app\user\model\Account;use app\user\model\User;use think\App;use think\facade\Cache;use think\facade\Validate;
+class Wechat extends Base{
+    protected $model=null;
+    protected $appid='';
+    protected $appsecret='';
+    protected $wechat=null;
+    protected $keepTime=3600;
+    protected $isLogin=0;
+    public function __construct(App $app) {
+        parent::__construct($app);
+        $this->appid = env('WECHAT.APPID');
+        $this->appsecret = env('WECHAT.APPSECRET');
+        $this->wechat = new \Wechat(['appid' => $this->appid, 'appsecret' => $this->appsecret]);
+    }
+
+   public function WebAuth(){
+	 	$code =$this->request->only(['code'=>''],'post','trim');
+		$valid =Validate::rule([
+			'code|微信授权Code'=>'require|max:255|min:5',
+			]);
+		if($valid->check($code)==false)return error($valid->getError());
+
+		$uid =$this->wechat->getAccessTokenByCode($code['code']);
+		if($uid==false)return error($this->wechat->errMsg);
+		if(!isset($uid['openid'])|| $uid['openid']=='')return error('用户openid 未获取到');
+		$userinfo = $this->checkOpendId($uid['openid']);
+		$wxinfo = $this->wechat->getUserInfo($uid['openid']);
+		 return success('获取成功',['wxinfo'=>$wxinfo,'userinfo'=>$userinfo,'isLogin'=>1]);
+    }
+    protected function checkOpendId($openId){
+        $accountId= User::where(['openId'=>$openId])->value('account_id',0);
+        if($accountId==0)return [];
+        $account =new Account();
+		$isT = $account->with(['accountItem'=>['itemName'],'company_relaton','userInfo'])
+		->findOrEmpty($accountId);
+		if($isT->isEmpty())return [];
+		$isT->hidden(['userInfo','password','salt','accountItem','openId']);
+		if ($isT->status==0) return error('账户已禁用');
+		$token = makeToken($isT);
+		\app\common\User::instance()->LoginUserInfo($isT->toArray(),$token,$this->keepTime);
+        $isT['token'] = $token;
+        $this->isLogin=1;
+        return $isT;
+	}
+
+	public function getConfig(){
+		$url =$this->request->only(['url'=>''],'post','trim');
+		$valid =Validate::rule(['url|微信授权地址'=>'require|max:255|min:5']);
+		if($valid->check($url)==false)return error($valid->getError());
+		$baseconfig =$this->wechat->getJsTicket();
+		if($baseconfig==false)return error('签名获取失败');
+		$baseconfig =$this->wechat->getJsSign($url['url']);
+		if($baseconfig==false)return error('签名获取失败');
+		return success('获取成功',$baseconfig);
+	}
+	
+	//获取公众号下定制模板
+	public function getTemplate(){
+		$template = Cache::get('Wx::Template');
+		if($template==false){
+			$data=$this->wechat->getAllPrivateTemplate();
+			if($data==false) return error($this->wechat->errMsg);
+			Cache::set('Wx::Template' ,$data['template_list'], new \DateTime(date('Y-m-d 23:59:59')) );
+			$template = $data['template_list'];
+		}
+		return success('获取成功',$template);
+	}
+
+
+}

+ 2 - 1
composer.json

@@ -26,7 +26,8 @@
         "topthink/think-filesystem": "^1.0",
         "topthink/think-multi-app": "^1.0",
         "topthink/think-helper": "^3.1",
-        "huaweicloud/huaweicloud-sdk-php": "^3.1"
+        "huaweicloud/huaweicloud-sdk-php": "^3.1",
+        "topthink/think-swoole": "2.0.*"
     },
     "require-dev": {
         "symfony/var-dumper": "^4.2",

+ 48 - 1
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "9e5a7b778cfaf2c0deba17a7b06eb7fe",
+    "content-hash": "97903c9dcbd9e568cfa5de66e9333558",
     "packages": [
         {
             "name": "guzzlehttp/guzzle",
@@ -1550,6 +1550,53 @@
                 "source": "https://github.com/top-think/think-orm/tree/v2.0.61"
             },
             "time": "2023-04-20T14:27:51+00:00"
+        },
+        {
+            "name": "topthink/think-swoole",
+            "version": "v2.0.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/top-think/think-swoole.git",
+                "reference": "501a2f104ac39db82414f79749adc8f032273613"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/top-think/think-swoole/zipball/501a2f104ac39db82414f79749adc8f032273613",
+                "reference": "501a2f104ac39db82414f79749adc8f032273613",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "ext-swoole": ">=1.8"
+            },
+            "type": "library",
+            "autoload": {
+                "files": [],
+                "psr-4": {
+                    "think\\swoole\\": "src"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "Apache-2.0"
+            ],
+            "authors": [
+                {
+                    "name": "liu21st",
+                    "email": "liu21st@gmail.com"
+                }
+            ],
+            "description": "Swoole extend for thinkphp5",
+            "support": {
+                "issues": "https://github.com/top-think/think-swoole/issues",
+                "source": "https://github.com/top-think/think-swoole/tree/2.0"
+            },
+            "time": "2018-06-22T08:21:06+00:00"
         }
     ],
     "packages-dev": [