shish 5 年 前
コミット
94dc5dde23

+ 87 - 13
app-pt/controllers/WxController.php

@@ -10,6 +10,7 @@ use bizHd\wx\classes\WxOpenClass;
 use bizHd\wx\services\WxBaseService;
 use bizHd\wx\services\WxOpenService;
 use bizHd\wx\services\WxSceneService;
+use common\components\dirUtil;
 use common\components\miniUtil;
 use Yii;
 use common\services\xhMerchantExtendService;
@@ -113,11 +114,13 @@ class WxController extends PublicController
         if ($style == dict::getDict('ptStyle', 'hd')) {
             //零售
             $merchant = WxOpenService::getWxInfo();
+            $isOpen = 1;
             if ($this->msgType == 'event') {
+
                 switch ($Event) {
                     //关注
                     case 'subscribe':
-                        $getUserInfo = wxUtil::userInfo($this->fromUsername, $merchant, 1);
+                        $getUserInfo = wxUtil::userInfo($this->fromUsername, $merchant, $isOpen);
                         $source = UserClass::$userSourceId['official']['name'];
                         $getUserInfo['subscribe'] = 1;
                         AdminService::replaceAdmin($getUserInfo, $source);
@@ -127,7 +130,7 @@ class WxController extends PublicController
                         $pc->encryptMsg($text, $timestamp, $nonce, $encryptMsg);//加密
                         //echo $encryptMsg;
 
-                        wxUtil::sendMiniMsg('123456789', $merchant, (string)$this->fromUsername, 1);
+                        wxUtil::sendMiniMsg('123456789', $merchant, (string)$this->fromUsername, $isOpen);
 
                         break;
                     //取消关注
@@ -140,21 +143,40 @@ class WxController extends PublicController
                         break;
                     default:
                 }
+
             } elseif ($this->msgType == 'miniprogrampage') {
-                Yii::info('1243 ' . $this->fromUsername . ' ' . json_encode($merchant));
+
+                //引导关注公众号
                 if ($postObj->PagePath == 'pagesClient/official/warn') {
-                    $r = miniUtil::sendMsg('123456', $merchant, (string)trim($this->fromUsername), 1);
-                    Yii::info('098' . ' ' . json_encode($r) . ' ' . $this->fromUsername . ' ' . json_encode($merchant));
+                    if (getenv('YII_ENV', 'local') == 'production') {
+                        $fullPathImg = dirUtil::getRootDir() . '/app-pt/web/img/gzh/hhbHd.jpg';
+                    } else {
+                        $fullPathImg = dirUtil::getRootDir() . '/app-pt/web/img/devGzh/hml.jpg';
+                    }
+                    $mediaKey = 'focus_img_' . $style . '_' . md5($fullPathImg);
+                    $mediaId = Yii::$app->redis->executeCommand('GET', [$mediaKey]);
+                    if (isset($mediaId) == false || empty($mediaId)) {
+                        $media = miniUtil::uploadTempMedia($merchant, $fullPathImg, $isOpen);
+                        $mediaId = $media['media_id'] ?? '';
+                        //二天有效期
+                        Yii::$app->redis->executeCommand('SETEX', [$mediaKey, 172800, $mediaId]);
+                    }
+                    if (!empty($mediaId)) {
+                        miniUtil::sendImgMsg($mediaId, $merchant, $this->fromUsername, $isOpen);
+                    }
                 }
+
             }
         } elseif ($style == dict::getDict('ptStyle', 'ghs')) {
+            $merchant = WxOpenClass::getGhsWxInfo();
+            $isOpen = 2;
             //供货商
             if ($this->msgType == 'event') {
+
                 switch ($Event) {
                     //关注
                     case 'subscribe':
-                        $merchant = WxOpenClass::getGhsWxInfo();
-                        $getUserInfo = wxUtil::userInfo($this->fromUsername, $merchant, 2);
+                        $getUserInfo = wxUtil::userInfo($this->fromUsername, $merchant, $isOpen);
                         $source = UserClass::$userSourceId['official']['name'];
                         $getUserInfo['subscribe'] = 1;
                         \bizGhs\admin\services\AdminService::replaceAdmin($getUserInfo, $source);
@@ -174,15 +196,40 @@ class WxController extends PublicController
                         break;
                     default:
                 }
+
+            } elseif ($this->msgType == 'miniprogrampage') {
+
+                //引导关注公众号
+                if ($postObj->PagePath == 'pagesClient/official/warn') {
+                    if (getenv('YII_ENV', 'local') == 'production') {
+                        $fullPathImg = dirUtil::getRootDir() . '/app-pt/web/img/gzh/xhb.jpg';
+                    } else {
+                        $fullPathImg = dirUtil::getRootDir() . '/app-pt/web/img/devGzh/hzg.jpg';
+                    }
+                    $mediaKey = 'focus_img_' . $style . '_' . md5($fullPathImg);
+                    $mediaId = Yii::$app->redis->executeCommand('GET', [$mediaKey]);
+                    if (isset($mediaId) == false || empty($mediaId)) {
+                        $media = miniUtil::uploadTempMedia($merchant, $fullPathImg, $isOpen);
+                        $mediaId = $media['media_id'] ?? '';
+                        //二天有效期
+                        Yii::$app->redis->executeCommand('SETEX', [$mediaKey, 172800, $mediaId]);
+                    }
+                    if (!empty($mediaId)) {
+                        miniUtil::sendImgMsg($mediaId, $merchant, $this->fromUsername, $isOpen);
+                    }
+                }
+
             }
         } elseif ($style == dict::getDict('ptStyle', 'mall')) {
+            $merchant = WxOpenClass::getMallWxInfo();
+            $isOpen = 3;
             //商城
             if ($this->msgType == 'event') {
+
                 switch ($Event) {
                     //关注
                     case 'subscribe':
-                        $merchant = WxOpenClass::getMallWxInfo();
-                        $getUserInfo = wxUtil::userInfo($this->fromUsername, $merchant, 3);
+                        $getUserInfo = wxUtil::userInfo($this->fromUsername, $merchant, $isOpen);
                         $source = UserClass::$userSourceId['official']['name'];
                         $getUserInfo['subscribe'] = 1;
                         UserService::replaceUser($getUserInfo, $source, 0);
@@ -202,6 +249,29 @@ class WxController extends PublicController
                         break;
                     default:
                 }
+
+            } elseif ($this->msgType == 'miniprogrampage') {
+
+                //引导关注公众号
+                if ($postObj->PagePath == 'pagesClient/official/warn') {
+                    if (getenv('YII_ENV', 'local') == 'production') {
+                        $fullPathImg = dirUtil::getRootDir() . '/app-pt/web/img/gzh/hhbHd.jpg';
+                    } else {
+                        $fullPathImg = dirUtil::getRootDir() . '/app-pt/web/img/devGzh/zhh.jpg';
+                    }
+                    $mediaKey = 'focus_img_' . $style . '_' . md5($fullPathImg);
+                    $mediaId = Yii::$app->redis->executeCommand('GET', [$mediaKey]);
+                    if (isset($mediaId) == false || empty($mediaId)) {
+                        $media = miniUtil::uploadTempMedia($merchant, $fullPathImg, $isOpen);
+                        $mediaId = $media['media_id'] ?? '';
+                        //二天有效期
+                        Yii::$app->redis->executeCommand('SETEX', [$mediaKey, 172800, $mediaId]);
+                    }
+                    if (!empty($mediaId)) {
+                        miniUtil::sendImgMsg($mediaId, $merchant, $this->fromUsername, $isOpen);
+                    }
+                }
+
             }
         } else {
             //其它
@@ -602,7 +672,8 @@ class WxController extends PublicController
     /**
      * 回复文字消息
      */
-    private function replyTextContent($content)
+    private
+    function replyTextContent($content)
     {
         $createTime = time();//响应当前时间
         $con = "<xml>
@@ -618,7 +689,8 @@ class WxController extends PublicController
     /**
      * 回复图片消息
      */
-    private function replyPicContent($media_id)
+    private
+    function replyPicContent($media_id)
     {
         $createTime = time();
         $con = "<xml>
@@ -636,7 +708,8 @@ class WxController extends PublicController
     /**
      * 回复单图文消息
      */
-    private function replyNewsContent($title, $desc, $picUrl, $url)
+    private
+    function replyNewsContent($title, $desc, $picUrl, $url)
     {
         $createTime = time();//响应当前时间
         $con = "<xml>
@@ -662,7 +735,8 @@ class WxController extends PublicController
      * @param $description
      * @return string
      */
-    private function replyVideoContent($title, $media_id, $description)
+    private
+    function replyVideoContent($title, $media_id, $description)
     {
 
         $createTime = time();//响应当前时间

BIN
app-pt/web/img/devGzh/hml.jpg


BIN
app-pt/web/img/devGzh/hzg.jpg


BIN
app-pt/web/img/devGzh/zhh.jpg


BIN
app-pt/web/img/gzh/hhbHd.jpg


BIN
app-pt/web/img/gzh/hhbMall.jpg


BIN
app-pt/web/img/gzh/xhb.jpg


+ 10 - 3
common/components/miniUtil.php

@@ -936,13 +936,20 @@ class miniUtil
     /**
      * 新增临时素材
      */
-    public static function uploadTempMedia($merchant, $imgUrl, $type = 'image', $isOpen = 1)
+    public static function uploadTempMedia($merchant, $fullPathImg, $isOpen, $type = 'image')
     {
         $accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
         $url = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token={$accessToken}&type=" . $type;
-        $postData = ['media' => '@' . $imgUrl];
         $ch = curl_init();
-        curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
+        if (class_exists('CURLFile')) {// 这里用特性检测判断php版本
+            curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
+            $postData = array('media' => new \CURLFile(realpath($fullPathImg)));//>=5.5
+        } else {
+            if (defined('CURLOPT_SAFE_UPLOAD')) {
+                curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
+                $postData = array('media' => '@' . realpath($fullPathImg));//<=5.5
+            }
+        }
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);