|
|
@@ -11,97 +11,103 @@ use linslin\yii2\curl;
|
|
|
|
|
|
class WxBaseClass extends BaseClass
|
|
|
{
|
|
|
-
|
|
|
- public static $baseFile = '\biz\wx\models\WxBase';
|
|
|
-
|
|
|
- //保存Logo shish 2020.3.11
|
|
|
- public static function saveLogo($url, $merchantId)
|
|
|
- {
|
|
|
- $path = dirUtil::getImgDir();
|
|
|
- $middle = "/wx/merchant/logo/";
|
|
|
- if (!file_exists($path . $middle)) {
|
|
|
- mkdir($path . $middle, 0777, true);
|
|
|
- }
|
|
|
- if (empty($merchantId)) {
|
|
|
- $merchantId = stringUtil::shortUniqueId($merchantId);
|
|
|
- }
|
|
|
- $name = $merchantId . '.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 . $merchantId . '_small.jpg';
|
|
|
- Image::thumbnail($fullFileName, $smallWidth, $smallHeight)->save($smallFullPathFile, ['quality' => 100]);
|
|
|
- return $fileName;
|
|
|
- }
|
|
|
-
|
|
|
- //保存公众号二维码 shish 2020.3.11
|
|
|
- public static function saveQrCode($url, $merchantId)
|
|
|
- {
|
|
|
- $path = dirUtil::getImgDir();
|
|
|
- $middle = "/wx/merchant/qrCode/";
|
|
|
- if (!file_exists($path . $middle)) {
|
|
|
- mkdir($path . $middle, 0777, true);
|
|
|
- }
|
|
|
- if (empty($merchantId)) {
|
|
|
- $merchantId = stringUtil::shortUniqueId($merchantId);
|
|
|
- }
|
|
|
- $name = $merchantId . '.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 . $merchantId . '_small.jpg';
|
|
|
- Image::thumbnail($fullFileName, $smallWidth, $smallHeight)->save($smallFullPathFile, ['quality' => 100]);
|
|
|
- return $fileName;
|
|
|
- }
|
|
|
+
|
|
|
+ public static $baseFile = '\biz\wx\models\WxBase';
|
|
|
+
|
|
|
+ //保存Logo shish 2020.3.11
|
|
|
+ public static function saveLogo($url, $merchantId)
|
|
|
+ {
|
|
|
+ $path = dirUtil::getImgDir();
|
|
|
+ $middle = "/wx/merchant/logo/";
|
|
|
+ if (!file_exists($path . $middle)) {
|
|
|
+ mkdir($path . $middle, 0777, true);
|
|
|
+ }
|
|
|
+ if (empty($merchantId)) {
|
|
|
+ $merchantId = stringUtil::shortUniqueId($merchantId);
|
|
|
+ }
|
|
|
+ $name = $merchantId . '.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 . $merchantId . '_small.jpg';
|
|
|
+ Image::thumbnail($fullFileName, $smallWidth, $smallHeight)->save($smallFullPathFile, ['quality' => 100]);
|
|
|
+ return $fileName;
|
|
|
+ }
|
|
|
+
|
|
|
+ //保存公众号二维码 shish 2020.3.11
|
|
|
+ public static function saveQrCode($url, $merchantId)
|
|
|
+ {
|
|
|
+ $path = dirUtil::getImgDir();
|
|
|
+ $middle = "/wx/merchant/qrCode/";
|
|
|
+ if (!file_exists($path . $middle)) {
|
|
|
+ mkdir($path . $middle, 0777, true);
|
|
|
+ }
|
|
|
+ if (empty($merchantId)) {
|
|
|
+ $merchantId = stringUtil::shortUniqueId($merchantId);
|
|
|
+ }
|
|
|
+ $name = $merchantId . '.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 . $merchantId . '_small.jpg';
|
|
|
+ Image::thumbnail($fullFileName, $smallWidth, $smallHeight)->save($smallFullPathFile, ['quality' => 100]);
|
|
|
+ return $fileName;
|
|
|
+ }
|
|
|
+
|
|
|
+ //取公众号信息 0表示平台的公众号 shish 2020.4.26
|
|
|
+ public static function getWxBase($id = 0)
|
|
|
+ {
|
|
|
+ return self::getByCondition(['merchantId' => 0]);
|
|
|
+ }
|
|
|
|
|
|
}
|