Selaa lähdekoodia

过去bug修改后补提交

qiushiyong 1 vuosi sitten
vanhempi
commit
914f01e8fe
3 muutettua tiedostoa jossa 65 lisäystä ja 40 poistoa
  1. 8 1
      App/Com/Sms.php
  2. 40 38
      App/Com/WechatAccessToken.php
  3. 17 1
      App/Crontab/BalanceCrontab.php

+ 8 - 1
App/Com/Sms.php

@@ -29,7 +29,14 @@ class Sms
         //小程序名称
         $operators_res = OperatorsUser::create()->where('id',$operators_id)->get()->toArray();
         $this->operators_name = $operators_res['key']?$operators_res['operators_name']:'前台优选';
-        $this->config['sign_name'] = $this->operators_name;
+        $sign_arr = [
+            '津辉优选',
+            '小富源选',
+            '国基乐购',
+            '喜相悦',
+            '方盒优选',
+        ];
+        $this->config['sign_name'] = in_array($this->operators_name, $sign_arr) ? $this->operators_name : '前台优选';
         $this->aliSms = new AliSms();
     }
 

+ 40 - 38
App/Com/WechatAccessToken.php

@@ -10,49 +10,51 @@ use EasySwoole\EasySwoole\Logger;
 class WechatAccessToken
 {
 
-	protected $redis = null;	//redis客户端
-	protected $url = "https://api.weixin.qq.com/cgi-bin/token";	//接口请求URL
-	protected $appid = null;	//appid
-	protected $secret = null;	//秘钥
-	protected $redis_save_key = 'wechat_access_token';	//redis中的缓存键值
-	protected $operators_id = 0;	//运营商ID
+    protected $redis = null;    //redis客户端
+    protected $url = "https://api.weixin.qq.com/cgi-bin/token";    //接口请求URL
+    protected $appid = null;    //appid
+    protected $secret = null;    //秘钥
+    protected $redis_save_key = 'wechat_access_token';    //redis中的缓存键值
+    protected $operators_id = 0;    //运营商ID
 
-	//构造函数
-	function __construct($operators_id=0){
-		$set = AccountWechat::create()->get()->toArray();
-		if($operators_id){
-			//获取运营商数据
-			$this->operators_id = $operators_id;
-            $operators_res = OperatorsUser::create()->where('id',$operators_id)->get()->toArray();
-            $set = $operators_res['wechat_appid']&&$operators_res['wechat_secret']?$operators_res:$set;
-            $this->redis_save_key = $operators_res['wechat_appid']&&$operators_res['wechat_secret']?$this->redis_save_key.'_'.$operators_id:$this->redis_save_key;
-		}
-		$this->appid = $set['wechat_appid'];
-		$this->secret = $set['wechat_secret'];
-	}
+    //构造函数
+    function __construct($operators_id = 0)
+    {
+        $set = AccountWechat::create()->get()->toArray();
+        if ($operators_id) {
+            //获取运营商数据
+            $this->operators_id = $operators_id;
+            $operators_res = OperatorsUser::create()->where('id', $operators_id)->get()->toArray();
+            $set = isset($operators_res['wechat_appid']) && $operators_res['wechat_appid'] && isset($operators_res['wechat_secret']) && $operators_res['wechat_secret'] ? $operators_res : $set;
+            $this->redis_save_key = isset($operators_res['wechat_appid']) && $operators_res['wechat_appid'] && isset($operators_res['wechat_secret']) && $operators_res['wechat_secret'] ? $this->redis_save_key . '_' . $operators_id : $this->redis_save_key;
+        }
+        $this->appid = $set['wechat_appid'];
+        $this->secret = $set['wechat_secret'];
+    }
 
 
-	/**
-	 * @param $operators_id 运营商ID,无运营商则为0
-	 * 获取Access_token
-	 * @return String 返回小程序授权码,获取失败可能会返回空
-	 */
-	public function getAccess_token(){
-		//加载redis
+    /**
+     * @param $operators_id 运营商ID,无运营商则为0
+     * 获取Access_token
+     * @return String 返回小程序授权码,获取失败可能会返回空
+     */
+    public function getAccess_token()
+    {
+        //加载redis
         $this->redis = Redis::getInstance()->getConnect();
         //获取redis存储
-        $result = json_decode($this->redis->get($this->redis_save_key),true);
+        $result = json_decode($this->redis->get($this->redis_save_key), true);
         //判断access_token不为空,且过期时间大于当前时间(去掉最后60秒防止时间误差)
-        if($result['access_token']&&$result['expires_time']>(time()-60)){
-        	return $result['access_token'];
-        }else{	//否者获取最新的access_token
-        	$response = file_get_contents($this->url."?grant_type=client_credential&appid=".$this->appid."&secret=".$this->secret);
-        	$result = json_decode($response,true);
-			//记录微信服务器返回值
-			Logger::getInstance()->info('小程序Access_token接口返回值:'.$response);
-			//缓存到Redis中
-			$this->redis->set($this->redis_save_key,json_encode(array('access_token'=>$result['access_token'],'expires_time'=>time()+$result['expires_in'])));
-			return $result['access_token'];
+        if ($result['access_token'] && $result['expires_time'] > (time() - 60)) {
+            return $result['access_token'];
+        } else {    //否者获取最新的access_token
+            $response = file_get_contents($this->url . "?grant_type=client_credential&appid=" . $this->appid . "&secret=" . $this->secret);
+            $result = json_decode($response, true);
+            //记录微信服务器返回值
+            Logger::getInstance()->info('小程序Access_token接口返回值:' . $response);
+            //缓存到Redis中
+            $this->redis->set($this->redis_save_key, json_encode(array('access_token' => $result['access_token'], 'expires_time' => time() + $result['expires_in'])));
+            return $result['access_token'];
         }
-	}
+    }
 }

+ 17 - 1
App/Crontab/BalanceCrontab.php

@@ -60,6 +60,14 @@ class BalanceCrontab implements JobInterface
     protected function push_start($task_id){
         $operators = explode(",",$this->set['operators']);
         foreach($operators as $value){
+
+            //----------------临时调试----------------
+//            if ($value != 46) {
+//                continue;
+//            }
+            //----------------临时调试----------------
+
+
             //查询该运营商用户的余额,上月消费记录等数据
             $startTime = strtotime(date('Y-m-01', strtotime('-1 month')));
             $endTime = strtotime(date('Y-m-t', strtotime('-1 month')))+86400;
@@ -78,6 +86,13 @@ class BalanceCrontab implements JobInterface
             $queryBuild->raw($que_sql);
             $res_data = DbManager::getInstance()->query($queryBuild, true, 'default')->toArray();
             foreach($res_data['result'] as $k=>$val){
+
+                //----------------临时调试----------------
+//                if (!in_array($val['mobile'], ['13410844128', '13823684008', '13600151177', '13544145803'])) {
+//                    continue;
+//                }
+                //----------------临时调试----------------
+
                 //插入推送内容
                 $insert = [
                     'task_id' => $task_id,
@@ -117,7 +132,8 @@ class BalanceCrontab implements JobInterface
                 'first' => ['value'=>'尊敬的客户:您上月共消费了'.$sendData['consume_credit'].'积分'],
                 'keyword1' => ['value'=>$sendData['balance']],
                 'keyword2' => ['value'=>date('Y年m月d日',$sendData['end_time'])],
-                'remark' => ['value'=>'欢迎登录「'.$sendData['operators_name'].'」小程序选购心仪的商品。'],
+//                'remark' => ['value'=>'欢迎登录「'.$sendData['operators_name'].'」小程序选购心仪的商品。'],
+                'remark' => ['value'=>'开工红包派发中,最高888元,点击领取', 'color' => '#E3170D'],
             ]);
             $status = $api_res['response']['errcode']!==0?2:1;  //0无响应 1成功 2失败