| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- namespace bizHd\wx\classes;
- use common\components\dirUtil;
- use common\components\stringUtil;
- use Yii;
- use bizHd\base\classes\BaseClass;
- use yii\imagine\Image;
- use linslin\yii2\curl;
- class WxBaseClass extends BaseClass
- {
-
- public static $baseFile = '\bizHd\wx\models\WxBase';
-
- //保存Logo ssh 2020.3.11
- public static function saveLogo($url, $sjId)
- {
- $path = dirUtil::getImgDir();
- $middle = "wx/merchant/logo/";
- if (!file_exists($path . $middle)) {
- mkdir($path . $middle, 0777, true);
- }
- if (empty($sjId)) {
- $sjId = stringUtil::shortUniqueId($sjId);
- }
- $name = $sjId . '.jpg';
- $fullFileName = $path . $middle . $name;
- $fileName = $middle . $name;
-
- if (file_exists($fullFileName)) {
- return $fileName;
- }
-
- $curl = new curl\Curl();
- $result = $curl->get($url);
-
- $fp = @fopen($fullFileName, 'a');
- fwrite($fp, $result);
- fclose($fp);
-
- $imgInfo = getimagesize($fullFileName);
- if (empty($imgInfo) || isset($imgInfo[0]) == false) {
- return '';
- }
- $width = $imgInfo[0];
- $height = $imgInfo[1];
-
- //生成小图 280px
- $smallWidth = 280;
- $smallHeight = ceil((280 * $height) / $width);
- if ($width <= 280) {
- $smallWidth = $width;
- $smallHeight = $height;
- }
- $smallFullPathFile = $path . $middle . $sjId . '_small.jpg';
- Image::thumbnail($fullFileName, $smallWidth, $smallHeight)->save($smallFullPathFile, ['quality' => 100]);
- return $fileName;
- }
-
- //保存公众号二维码 ssh 2020.3.11
- public static function saveQrCode($url, $sjId)
- {
- $path = dirUtil::getImgDir();
- $middle = "wx/merchant/qrCode/";
- if (!file_exists($path . $middle)) {
- mkdir($path . $middle, 0777, true);
- }
- if (empty($sjId)) {
- $sjId = stringUtil::shortUniqueId($sjId);
- }
- $name = $sjId . '.jpg';
- $fullFileName = $path . $middle . $name;
- $fileName = $middle . $name;
-
- if (file_exists($fullFileName)) {
- return $fileName;
- }
-
- $curl = new curl\Curl();
- $result = $curl->get($url);
-
- $fp = @fopen($fullFileName, 'a');
- fwrite($fp, $result);
- fclose($fp);
-
- $imgInfo = getimagesize($fullFileName);
- if (empty($imgInfo) || isset($imgInfo[0]) == false) {
- return '';
- }
- $width = $imgInfo[0];
- $height = $imgInfo[1];
-
- //生成小图 280px
- $smallWidth = 280;
- $smallHeight = ceil((280 * $height) / $width);
- if ($width <= 280) {
- $smallWidth = $width;
- $smallHeight = $height;
- }
- $smallFullPathFile = $path . $middle . $sjId . '_small.jpg';
- Image::thumbnail($fullFileName, $smallWidth, $smallHeight)->save($smallFullPathFile, ['quality' => 100]);
- return $fileName;
- }
- //取公众号信息 0表示平台的公众号 ssh 2020.4.26
- public static function getWxBase($id = 0)
- {
- return self::getByCondition(['sjId' => 0]);
- }
- }
|