Browse Source

add wx mini push message

stanley-king 4 years ago
parent
commit
ac4fb4df1a

+ 58 - 2
data/logic/queue.logic.php

@@ -28,7 +28,8 @@ require_once(BASE_HELPER_PATH . '/search/tcp_client.php');
 require_once(BASE_HELPER_PATH . '/ugc_helper.php');
 require_once(BASE_HELPER_PATH . '/room_helper.php');
 require_once(BASE_HELPER_PATH . '/mcard/mcard.php');
-
+require_once(BASE_HELPER_PATH . '/util_helper.php');
+require_once(BASE_HELPER_PATH . '/third_author/signaturer.php');
 
 class queueLogic
 {
@@ -73,6 +74,61 @@ class queueLogic
         }
     }
 
+    public function makeMemberMiniQrCode($params)
+    {
+        $member_id = intval($params['member_id']);
+        $resp = thrid_author\signaturer::instance()->minicode("/pages/index/index?relay_id={$member_id}&channel=0",430);
+
+        if(!empty($resp))
+        {
+            $passwd = util::passwd;
+            $name = md5("{$member_id}.{$passwd}") . ".png";
+
+            $save_path = BASE_UPLOAD_PATH . DS . ATTACH_MINI_QRCODE . DS . $name;
+            $length = file_put_contents($save_path,$resp);
+            if(!$length) {
+                Log::record("Cannot write file: {$save_path}",Log::ERR);
+            }
+        }
+        else {
+            Log::record("request mini code error when member_id = {$member_id}",Log::ERR);
+        }
+    }
+
+    //邀请好友成功后向,邀请者发送微信push消息。
+    public function sendInviterSubMsg($params)
+    {
+        $inviter_id = $params['inviter_id'];
+        $invitee_id = $params['invitee_id'];
+
+        $mod_member = Model('member');
+        $items = $mod_member->field('member_id,member_wxopenid,member_nickname,member_time')
+                            ->where(['member_id' => ['in',[$inviter_id,$invitee_id]]])
+                            ->select();
+        foreach ($items as $item) {
+            if($item['member_id'] == $inviter_id) {
+                $inviter = $item;
+            }
+            else {
+                $invitee = $item;
+            }
+        }
+        if(empty($inviter) || empty($invitee) || empty($inviter['member_wxopenid'])) {
+            return callback(false, '向邀请者发送微信push消息错误');
+        }
+        $tmpid = 'zBNktaey9EM2DcBzUNsjnAan2NvYpj_nKZDY__f9pGA'; //这个是
+
+        $openid = $inviter['member_wxopenid'];
+        $time = strftime('%Y年%m月%d日',$invitee['member_time']);
+        $data = ['thing4' => ['value' => $invitee['member_nickname'] ], 'time3' => ['value' => "{$time}"]];
+        $ret = thrid_author\signaturer::instance()->send_submsg($openid,$tmpid,'pages/index/index',$data);
+        if($ret) {
+            return callback(true, "向邀请者{$inviter_id}发送微信push消息成功");
+        } else {
+            return callback(false, "向邀请者{$inviter_id}发送微信push消息错误");
+        }
+    }
+
     /**
      * 更新使用的代金券状态
      * @param $input_voucher_list
@@ -83,7 +139,7 @@ class queueLogic
         $model_voucher = Model('voucher');
         $send = new memsg\message_sender();
         foreach ($voucher_list as $store_id => $voucher_info) {
-            $update = $model_voucher->editVoucher(array('voucher_state' => 2), array('voucher_id' => $voucher_info['voucher_id']), $voucher_info['voucher_owner_id']);
+            $update = $model_voucher->editVoucher(['voucher_state' => 2], ['voucher_id' => $voucher_info['voucher_id']], $voucher_info['voucher_owner_id']);
             if ($update) {
                 // 发送用户店铺消息
                 $send->set('member_id', $voucher_info['voucher_owner_id']);

+ 1 - 0
docker-compose-dev.yml

@@ -74,6 +74,7 @@ services:
       - $PWD/conf/etc/localtime:/etc/localtime:ro
       - $PWD/conf/php/php-debug.ini:/usr/local/etc/php/php.ini
       - $PWD:/var/www/html
+      - /Volumes/Transcend/upload:/var/www/html/data/upload
     links:
       - redisrv
     container_name: "panda-php"

+ 1 - 0
global.php

@@ -65,6 +65,7 @@ define('ATTACH_CMS','cms');
 define('ATTACH_LIVE','live');
 define('ATTACH_MALBUM', ATTACH_PATH.'/member');
 define('ATTACH_MQRCODE',ATTACH_PATH.'/qrcode');
+define('ATTACH_MINI_QRCODE',ATTACH_PATH.'/mqrcode');
 define('ATTACH_MICROSHOP','microshop');
 define('TPL_SHOP_NAME','default');
 define('TPL_CIRCLE_NAME', 'default');

+ 3 - 5
helper/account_helper.php

@@ -45,11 +45,6 @@ require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
 
 class account_helper
 {
-    public static function calc_vorder_amount($goods_info,$userid)
-    {
-
-    }
-
     ///
     public static function invite_bonus($relay_id)
     {
@@ -399,6 +394,9 @@ class account_helper
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     public static function onRegister($member_id,$relay_id)
     {
+        QueueClient::push('makeMemberMiniQrCode',['member_id' => $member_id]);
+        QueueClient::push('sendInviterSubMsg', ['inviter_id' => $relay_id,'invitee_id' => $member_id]);
+
         if(session_helper::isapp()) {
             $updata['client_type'] = session_helper::client_type();
             $updata['client_version'] = session_helper::version_code();

+ 5 - 2
helper/sensitive_word/dfa.php

@@ -1,4 +1,5 @@
 <?php
+declare(strict_types=0);
 
 class DFAFilter
 {
@@ -109,13 +110,15 @@ class DFAFilter
                         $ret[] = $uc;
                         $i += 3;
                     }
-                } else if (($c & 0xf0) == 0xe0 && $len - $i >= 3) {
+                }
+                elseif (($c & 0xf0) == 0xe0 && $len - $i >= 3) {
                     if ((ord($str[$i + 1]) & 0xc0) == 0x80 && (ord($str[$i + 2]) & 0xc0) == 0x80) {
                         $uc = substr($str, $i, 3);
                         $ret[] = $uc;
                         $i += 2;
                     }
-                } else if (($c & 0xe0) == 0xc0 && $len - $i >= 2) {
+                }
+                elseif (($c & 0xe0) == 0xc0 && $len - $i >= 2) {
                     if ((ord($str[$i + 1])  & 0xc0) == 0x80) {
                         $uc = substr($str, $i, 2);
                         $ret[] = $uc;

+ 22 - 1
helper/third_author/signaturer.php

@@ -24,6 +24,7 @@ class signaturer
     const ticket_url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket";
     const createwxaqrcode_url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode";
     const getwxacode_url = "https://api.weixin.qq.com/wxa/getwxacode";
+    const send_submsg_url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send";
 
     const prefix = 'signaturer';
     const try_sleep = 5;
@@ -70,10 +71,30 @@ class signaturer
         $param = ['path' => $path,'width' => $width];
         $url = self::getwxacode_url . "?access_token={$access_token}";
         $resp = http_post_data($url,json_encode($param));
-
         return $resp;
     }
 
+    public function send_submsg($openid,$tmpid,$page,$data)
+    {
+        $token = $this->access_token();
+        if($token == false) return false;
+
+
+        $access_token = $token['token'];
+        $url = self::send_submsg_url . "?access_token={$access_token}";
+        $param = ['touser' => $openid,'template_id' => $tmpid,'page' => $page,'data' => $data];
+
+        $resp = http_post_data($url,json_encode($param));
+        $resp = json_decode($resp,true);
+        if($resp['errcode'] == 0  || $resp['errmsg'] == 'ok') {
+            return true;
+        }
+        else {
+            Log::record("send_submsg errmsg:{$resp['errmsg']}",Log::ERR);
+            return false;
+        }
+    }
+
     private function noncestr($length = 16)
     {
         $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

+ 14 - 0
mobile/control/member_info.php

@@ -267,6 +267,7 @@ class member_infoControl extends mbMemberControl
         $ret['is_vip'] = session_helper::isVip();
         $card_list =  mtopcard\priority_cards(session_helper::memberid());
         $ret['cards'] = mtopcard\topcard_format($card_list);
+        $ret['mini_code'] = $this->mini_code();
 
         $usercards = new mcard\user_mcards(session_helper::memberid());
         $ret['vip_left_amount'] = $usercards->left_amount();
@@ -276,4 +277,17 @@ class member_infoControl extends mbMemberControl
         }
         return $ret;
     }
+    private function mini_code()
+    {
+        $uid = session_helper::memberid();
+        $passwd = util::passwd;
+        $name = md5("{$uid}.{$passwd}") . ".png";
+        $save_path = BASE_UPLOAD_PATH . DS . ATTACH_MINI_QRCODE . DS . $name;
+        $url = UPLOAD_SITE_URL . DS . ATTACH_MINI_QRCODE . DS . $name;
+
+        if(!file_exists($save_path)) {
+            QueueClient::push('makeMemberMiniQrCode',['member_id' => $uid]);
+        }
+        return $url;
+    }
 }

+ 0 - 1
test/TestMemberCard.php

@@ -40,7 +40,6 @@ class TestMemberCard extends TestCase
         if($now > $nine || $now < $twenty_first) {
             $x = 0;
         }
-
     }
 
 

+ 36 - 2
test/TestQRcode.php

@@ -26,8 +26,42 @@ class TestQRcode extends TestCase
 
     public function testMiniCode()
     {
-        $resp = thrid_author\signaturer::instance()->minicode('/pages/index/index?relay_id=52620&channel=0',430);
-        file_put_contents('x.png',$resp);
+        $member_id = 52620;
+
+        $queue = Logic('queue');
+        $queue->makeMemberMiniQrCode(['member_id' => $member_id]);
+        $url = $this->mini_code($member_id);
+    }
+
+    public function testSendInviter()
+    {
+        $inviter_id = 52640;
+        $invitee_id = 52638;
+
+        $queue_logic = Logic('queue');
+        $queue_logic->sendInviterSubMsg(['inviter_id' => $inviter_id,'invitee_id' => $invitee_id]);
+
+        $openid = 'ocimY5Bi5voa71ejczOUmxqsDgtU';
+        $tmpid = 'zBNktaey9EM2DcBzUNsjnAan2NvYpj_nKZDY__f9pGA';
+
+        $time = '2020年8月7日';
+        $data = ['thing4' => ['value' => '江南'], 'time3' => ['value' => "{$time}"]];
+
+        thrid_author\signaturer::instance()->send_submsg($openid,$tmpid,'pages/index/index',$data);
+    }
+
+
+    private function mini_code($uid)
+    {
+        $passwd = util::passwd;
+        $name = md5("{$uid}.{$passwd}") . ".png";
+        $save_path = BASE_UPLOAD_PATH . DS . ATTACH_MINI_QRCODE . DS . $name;
+        $url = UPLOAD_SITE_URL . DS . ATTACH_MINI_QRCODE . DS . $name;
+
+        if(!file_exists($save_path)) {
+            QueueClient::push('makeMemberMiniQrCode',['member_id' => $uid]);
+        }
+        return $url;
     }
 
     public function testPgenA()