Przeglądaj źródła

更新 公众号

shish 6 lat temu
rodzic
commit
930b57d3ca

+ 8 - 5
app/www/controllers/WxOpenController.php

@@ -6,6 +6,7 @@ use biz\ad\classes\AdClass;
 use biz\goods\classes\CategoryClass;
 use biz\merchant\classes\MerchantExtendClass;
 use biz\merchant\services\MerchantService;
+use biz\weixin\classes\WxAccountClass;
 use biz\weixin\services\WxOpenService;
 use common\services\xhMerchantExtendService;
 use Yii;
@@ -154,12 +155,14 @@ class WxOpenController extends PublicController
 			Yii::info('小程序信息更新成功:' . json_encode($authorize_info));
 			util::stop("小程序信息更新成功");
 		}
-		
+
 		$upData = [];
 		$appData['wxUserName'] = $user_name;
 		$appData['wxAliasName'] = $alias;
-		$upData['logo'] = xhMerchantService::logoSave($head_img, $authorizeAppId);//公众号logo
-		$upData['wxQrcodeUrl'] = xhMerchantService::qrCodeSave($qrCodeUrl, $authorizeAppId);//公众号二维码
+		//公众号logo
+		$upData['logo'] = WxAccountClass::saveLogo($head_img,$id);
+		//公众号二维码
+		$upData['wxQrCodeUrl'] = WxAccountClass::saveQrCode($qrCodeUrl,$id);
 		$upData['wxAppId'] = $authorizeAppId;
 		$upData['wxAccessToken'] = $authorize_access_token;
 		$upData['wxAccessTokenTime'] = $accessTokenTime;
@@ -175,10 +178,10 @@ class WxOpenController extends PublicController
 			$msg = serialize($data);
 			$producer->publish($msg, 'openShopInitExchange', 'openShopInitRoute');
 		}
-		
+
 		echo 'ok';
 	}
-	
+
 	public function actionResult()
 	{
 		$get = Yii::$app->request->get();

+ 86 - 2
biz/weixin/classes/WxAccountClass.php

@@ -4,10 +4,94 @@ namespace biz\weixin\classes;
 
 use Yii;
 use biz\base\classes\BaseClass;
+use yii\imagine\Image;
 
 class WxAccountClass extends BaseClass
 {
-
+	
 	public static $baseFile = '\biz\weixin\models\WxAccount';
-
+	
+	public static function saveLogo($url, $merchantId)
+	{
+		$path = dirUtil::getImgDir();
+		$middle = "/wx/merchant/logo/";
+		if (!file_exists($path . $middle)) {
+			mkdir($path . $middle, 0777, true);
+		}
+		$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 function saveQrCode($url, $merchantId)
+	{
+		$path = dirUtil::getImgDir();
+		$middle = "/wx/merchant/qrCode/";
+		if (!file_exists($path . $middle)) {
+			mkdir($path . $middle, 0777, true);
+		}
+		$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;
+	}
+	
 }

+ 4 - 3
biz/weixin/classes/WxOpenClass.php

@@ -13,7 +13,8 @@ class WxOpenClass extends BaseClass
 	//平台管理员的手机号
 	const ADMIN_MOBILE = 15280215347;
 	const PLATFORM_ACCOUNT = 12359;
-	
+	const ID = 1;
+
 	//取平台的帐号
 	public static function getPlatformAccount()
 	{
@@ -23,9 +24,9 @@ class WxOpenClass extends BaseClass
 	//获取开放平台 shish 2020.2.11
 	public static function getOpen()
 	{
-		return self::getById(1);
+		return self::getById(self::ID);
 	}
-	
+
 	//获取平台管理员的手机号 shish 2020.3.4
 	public static function getAdminMobile()
 	{

+ 5 - 8
common/components/wxUtil.php

@@ -2,6 +2,7 @@
 
 namespace common\components;
 
+use biz\weixin\classes\WxOpenClass;
 use common\services\xhMerchantExtendService;
 use Yii;
 use yii\helpers\Json;
@@ -1490,14 +1491,11 @@ class wxUtil
 		$result = Json::decode($result);
 		return $result;
 	}
-	
-	/**
-	 * 微信开放平台获取授权方的公众号帐号基本信息
-	 */
+
+	//微信开放平台获取授权方的公众号帐号基本信息 shish 2020.3.11
 	public static function getAuthorizerInfo($authorizerAppId)
 	{
-		$id = configDict::getConfig('openId');
-		$open = xhWxOpenService::getById($id);
+		$open = WxOpenClass::getOpen();
 		$appId = $open['appId'];
 		$accessToken = self::getComponentAccessToken($open);
 		$url = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token={$accessToken}";
@@ -1507,6 +1505,5 @@ class wxUtil
 		$result = Json::decode($result);
 		return $result;
 	}
-	
-	
+
 }

+ 1 - 1
common/services/ImageService.php

@@ -17,7 +17,7 @@ class ImageService
 		$month = date("Ym");
 		$date = date("d");
 		$path = dirUtil::getImgDir();
-		$middle = "/uploads/weixin/avatar/{$merchantId}/{$month}/{$date}/";
+		$middle = "/wx/avatar/{$merchantId}/{$month}/{$date}/";
 		if (!file_exists($path . $middle)) {
 			mkdir($path . $middle, 0777, true);
 		}

+ 28 - 9
console/controllers/UpgradeController.php

@@ -7,6 +7,7 @@ use biz\goods\services\GoodsService;
 use biz\goods\services\GoodsStyleService;
 use biz\merchant\services\MerchantCapitalService;
 use biz\merchant\services\MerchantExtendService;
+use biz\merchant\services\MerchantService;
 use biz\message\services\TMessageService;
 use biz\order\services\OrderGoodsService;
 use biz\order\services\OrderService;
@@ -21,6 +22,7 @@ use biz\user\services\UserService;
 use biz\weixin\services\WxMenuService;
 use common\components\dirUtil;
 use common\components\util;
+use common\components\wxUtil;
 use common\services\xhMerchantService;
 use common\services\xhWxMenuService;
 use Yii;
@@ -1193,11 +1195,11 @@ ALTER TABLE `xhUserGrowth` DROP COLUMN `capitalType`;";
 		
 		$sql = "ALTER TABLE `xhOrder` MODIFY `discountType` TINYINT NOT NULL DEFAULT 0 COMMENT '优惠类型 0没有优惠 1使用优惠卷 2会员打折 3随机优惠';";
 		Yii::$app->db->createCommand($sql)->execute($sql);
-
+		
 		//增加常规的节日 shish 2020.3.11
 		$sql = "INSERT  INTO `xhFest`(`id`,`name`,`month`,`day`,`inTurn`) VALUES (1,'情人节',2,14,0),(2,'母亲节',5,10,0),(3,'教师节',9,10,0),(4,'七夕节',8,25,0),(5,'妇女节',3,8,0),(6,'女生节',3,7,0);";
 		Yii::$app->db->createCommand($sql)->execute($sql);
-
+		
 		//将商家的logo清除掉
 		$sql = "UPDATE xhMerchant SET `logo`='';";
 		Yii::$app->db->createCommand($sql)->execute($sql);
@@ -1210,16 +1212,24 @@ merchantId INT NOT NULL DEFAULT 0 COMMENT '商家id',
 `addTime` INT NOT NULL DEFAULT 0 COMMENT '添加时间'
 )COMMENT='微信公众号';";
 		Yii::$app->db->createCommand($sql)->execute($sql);
-
+		
+		$sql = "ALTER TABLE xhWxAccount ADD `logo` VARCHAR(500) NOT NULL DEFAULT '' COMMENT '公众号logo' AFTER `id`;
+ALTER TABLE xhMerchant MODIFY `logo` VARCHAR(500) NOT NULL DEFAULT '' COMMENT '商家logo';";
+		Yii::$app->db->createCommand($sql)->execute($sql);
+		
+		//公众号二维码
+		$sql = "ALTER TABLE `xhMerchant` CHANGE `wxQrcodeUrl` `wxQrCodeUrl` VARCHAR(500) NOT NULL DEFAULT '' COMMENT '公众号二维码';";
+		Yii::$app->db->createCommand($sql)->execute($sql);
+		
 	}
 	
 	//数据迁移 shish 2020.1.12
 	//./yii upgrade/sync
 	public function actionSync()
 	{
-
+		
 		//国兰和花卉宝的logo要重新补进去!!!!!
-
+		
 		//国兰老客户导入
 		$oldUserList = Yii::$app->db2->createCommand('select * from xhUserOldData where `status`=0')->queryAll();
 		if (!empty($oldUserList)) {
@@ -1301,10 +1311,10 @@ merchantId INT NOT NULL DEFAULT 0 COMMENT '商家id',
 				}
 			}
 		}
-
+		
 		//头像丢失了更新头像
 		UserService::syncAvatar(12358);
-
+		
 	}
 	
 	//微信菜单初始化或重置,可以重复执行 shish 2020.3.5
@@ -1314,18 +1324,27 @@ merchantId INT NOT NULL DEFAULT 0 COMMENT '商家id',
 		$merchant = xhMerchantService::getById($id);
 		xhWxMenuService::applyInit($merchant);
 	}
-
+	
 	//测试生成头像有没问题
 	public function actionAddAvatar($id)
 	{
 		UserService::deleteByCondition(['merchantId' => $id]);
 		UserService::syncWxAllUser($id);
 	}
-
+	
 	//更新头像 shish 2020.3.10
 	public function actionUpdateAvatar($id)
 	{
 		UserService::syncAvatar($id);
 	}
+
+	//更新公众号的头像和二维码 shish 2020.3.11
+	public function actionUpdateImg($id)
+	{
+		$merchant = MerchantService::getMerchantById($id);
+		$appId = $merchant['wxAppId'];
+		$info = wxUtil::getAuthorizerInfo($appId);
+		print_r($info);
+	}
 	
 }