shish 5 lat temu
rodzic
commit
33832c3ecf

+ 14 - 13
app/pt/controllers/WxOpenController.php

@@ -59,9 +59,21 @@ class WxOpenController extends PublicController
 			util::stop('公众号授权回调未成功');
 		}
 		$id = $get['id'] ?? 'hd';
+		
+		$open = [];
+		if ($id == 'hd') {
+			$open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_HD]);
+		}
+		if ($id == 'ghs') {
+			$open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_GHS]);
+		}
+		if (empty($open)) {
+			util::stop('没有找到平台信息');
+		}
+		
 		$code = $get['auth_code'];
 		//使用授权码换取公众号的接口调用凭据和授权信息
-		$authorize = wxUtil::getAuthorizer($code);
+		$authorize = wxUtil::getAuthorizer($code,$open);
 		if (isset($authorize['authorization_info']) == false) {
 			util::stop('未换取公众号的接口调用凭据和授权信息');
 		}
@@ -71,7 +83,7 @@ class WxOpenController extends PublicController
 		$expires_in = $info['expires_in'];//7200
 		$authorize_refresh_token = $info['authorizer_refresh_token'];
 		//获取授权方的公众号帐号基本信息
-		$authorizeDetailInfo = wxUtil::getAuthorizerInfo($authorizeAppId);
+		$authorizeDetailInfo = wxUtil::getAuthorizerInfo($authorizeAppId,$open);
 		if (isset($authorizeDetailInfo['authorizer_info']) == false) {
 			util::stop('没有获取到公众号帐号基本信息');
 		}
@@ -106,17 +118,6 @@ class WxOpenController extends PublicController
 			$sjWxInfo = MerchantExtendClass::getByMerchantId($id);
 		}
 		
-		$open = [];
-		if ($id == 'hd') {
-			$open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_HD]);
-		}
-		if ($id == 'ghs') {
-			$open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_GHS]);
-		}
-		if (empty($open)) {
-			util::stop('没有找到平台信息');
-		}
-		
 		//如果授权的是小程序
 		if (isset($authorize_info['MiniProgramInfo']) && !empty($authorize_info['MiniProgramInfo'])) {
 			if (isset($sjWxInfo['miniAppId']) && !empty($sjWxInfo['miniAppId'])) {

+ 0 - 27
biz-ghs/merchant/services/MerchantService.php

@@ -189,33 +189,6 @@ class MerchantService extends BaseService
         }
     }
 
-    //初始化平台的商家 shish 2020.2.11
-    public static function initOpenMerchant()
-    {
-        $open = WxOpenClass::getOpen();
-        if (isset($open['wxBaseId']) && !empty($open['wxBaseId']) && isset($open['wxMiniBaseId']) && !empty($open['wxMiniBaseId'])) {
-            util::stop('已初始化,无需重复操作');
-        }
-        $env = getenv('YII_ENV');
-        switch ($env) {
-            case 'local':
-                $merchantName = '花美灵';
-                break;
-            case 'dev':
-                $merchantName = '花美灵';
-                break;
-            case 'test':
-                $merchantName = '花掌柜';
-                break;
-            case 'production':
-                $merchantName = '花卉宝';
-                break;
-            default:
-                $merchantName = '花卉宝';
-        }
-        echo $merchantName;
-    }
-
     //获取商家的h5商城二维码 shish 2020.4.30
     public static function getH5MallQrCode($id)
     {

+ 118 - 106
biz-hd/wx/classes/WxOpenClass.php

@@ -9,110 +9,122 @@ use bizHd\base\classes\BaseClass;
 
 class WxOpenClass extends BaseClass
 {
-
-    public static $baseFile = '\bizHd\wx\models\WxOpen';
-
-    //平台管理员的手机号
-    const ADMIN_MOBILE = 15280215347;
-    const PLATFORM_ACCOUNT = 12359;
-    const ID = 1;
-
-    //取平台的帐号
-    public static function getPlatformAccount()
-    {
-        return self::PLATFORM_ACCOUNT;
-    }
-
-    //获取平台基础信息 shish 2020.2.11
-    public static function getOpen()
-    {
-        return self::getById(self::ID);
-    }
-
-    //获取平台管理员的手机号 shish 2020.3.4
-    public static function getAdminMobile()
-    {
-        return self::ADMIN_MOBILE;
-    }
-
-    //获取平台微信信息
-    public static function getOpenInfo()
-    {
-        $open = self::getById(self::ID);
-        if (isset($open['merchantId']) && !empty($open['merchantId'])) {
-            $merchantId = $open['merchantId'];
-            return MerchantClass::getMerchantById($merchantId);
-        }
-        util::fail('没有找到平台信息');
-    }
-
-    //更新开放平台信息 shish 2020.4.13
-    public static function updateOpen($data)
-    {
-        self::updateById(self::ID, $data);
-    }
-
-    //平台小程序信息 shish 2020.4.13
-    public static function getWxMiniBase()
-    {
-        $open = self::getOpen();
-        $wxMiniBaseId = isset($open['wxMiniBaseId']) ? $open['wxMiniBaseId'] : 0;
-        $base = WxMiniBaseClass::getById($wxMiniBaseId);
-        if (empty($base)) {
-            util::fail('没有找到平台小程序信息');
-        }
-        return $base;
-    }
-
-    //公众号信息 shish 2020.4.14
-    public static function getWxBase()
-    {
-        $open = self::getOpen();
-        $wxBaseId = isset($open['wxBaseId']) ? $open['wxBaseId'] : 0;
-        $base = WxBaseClass::getById($wxBaseId);
-        if (empty($base)) {
-            util::fail('没有找到平台公众号信息');
-        }
-        return $base;
-    }
-
-    //获取微信和小程序信息 shish 2020.4.14
-    public static function getWxInfo()
-    {
-        $mini = self::getWxMiniBase();
-        $wx = self::getWxBase();
-        return array_merge($wx, $mini);
-    }
-
-    //公众号信息 shish 2020.4.14
-    public static function getGhsWxBase()
-    {
-        $open = self::getOpen();
-        $wxGhsBaseId = isset($open['wxGhsBaseId']) ? $open['wxGhsBaseId'] : 0;
-        $base = WxBaseClass::getById($wxGhsBaseId);
-        if (empty($base)) {
-            util::fail('没有找到平台公众号信息');
-        }
-        return $base;
-    }
-
-    //平台小程序信息 shish 2020.4.13
-    public static function getGhsWxMiniBase()
-    {
-        $open = self::getOpen();
-        $wxGhsMiniBaseId = isset($open['wxGhsMiniBaseId']) ? $open['wxGhsMiniBaseId'] : 0;
-        $base = WxMiniBaseClass::getById($wxGhsMiniBaseId);
-        if (empty($base)) {
-            util::fail('没有找到平台小程序信息');
-        }
-        return $base;
-    }
-
-    public static function getGhsWxInfo()
-    {
-        $mini = self::getGhsWxMiniBase();
-        $wx = self::getGhsWxBase();
-        return array_merge($wx, $mini);
-    }
-
+	
+	public static $baseFile = '\bizHd\wx\models\WxOpen';
+	
+	//平台管理员的手机号
+	const ADMIN_MOBILE = 15280215347;
+	const PLATFORM_ACCOUNT = 12359;
+	const ID = 1;
+	
+	//取平台的帐号
+	public static function getPlatformAccount()
+	{
+		return self::PLATFORM_ACCOUNT;
+	}
+	
+	//获取平台基础信息 shish 2020.2.11
+	public static function getOpen()
+	{
+		return self::getById(self::ID);
+	}
+	
+	//获取平台管理员的手机号 shish 2020.3.4
+	public static function getAdminMobile()
+	{
+		return self::ADMIN_MOBILE;
+	}
+	
+	//获取平台微信信息
+	public static function getOpenInfo()
+	{
+		$open = self::getById(self::ID);
+		if (isset($open['merchantId']) && !empty($open['merchantId'])) {
+			$merchantId = $open['merchantId'];
+			return MerchantClass::getMerchantById($merchantId);
+		}
+		util::fail('没有找到平台信息');
+	}
+	
+	//更新开放平台信息 shish 2020.4.13
+	public static function updateOpen($data)
+	{
+		self::updateById(self::ID, $data);
+	}
+	
+	//平台小程序信息 shish 2020.4.13
+	public static function getWxMiniBase()
+	{
+		$open = self::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_HD]);
+		if (empty($open)) {
+			util::fail('没有找到花店平台信息...');
+		}
+		$wxMiniBaseId = isset($open['wxMiniBaseId']) ? $open['wxMiniBaseId'] : 0;
+		$base = WxMiniBaseClass::getById($wxMiniBaseId);
+		if (empty($base)) {
+			util::fail('没有找到平台小程序信息');
+		}
+		return $base;
+	}
+	
+	//公众号信息 shish 2020.4.14
+	public static function getWxBase()
+	{
+		$open = self::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_HD]);
+		if (empty($open)) {
+			util::fail('没有找到花店平台信息...');
+		}
+		$wxBaseId = isset($open['wxBaseId']) ? $open['wxBaseId'] : 0;
+		$base = WxBaseClass::getById($wxBaseId);
+		if (empty($base)) {
+			util::fail('没有找到平台公众号信息');
+		}
+		return $base;
+	}
+	
+	//获取微信和小程序信息 shish 2020.4.14
+	public static function getWxInfo()
+	{
+		$mini = self::getWxMiniBase();
+		$wx = self::getWxBase();
+		return array_merge($wx, $mini);
+	}
+	
+	//公众号信息 shish 2020.4.14
+	public static function getGhsWxBase()
+	{
+		$open = self::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_GHS]);
+		if (empty($open)) {
+			util::fail('没有找到供货商平台信息...');
+		}
+		$wxGhsBaseId = isset($open['wxGhsBaseId']) ? $open['wxGhsBaseId'] : 0;
+		$base = WxBaseClass::getById($wxGhsBaseId);
+		if (empty($base)) {
+			util::fail('没有找到平台公众号信息');
+		}
+		return $base;
+	}
+	
+	//平台小程序信息 shish 2020.4.13
+	public static function getGhsWxMiniBase()
+	{
+		$open = self::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_GHS]);
+		if (empty($open)) {
+			util::fail('没有找到供货商平台信息...');
+		}
+		$wxGhsMiniBaseId = isset($open['wxGhsMiniBaseId']) ? $open['wxGhsMiniBaseId'] : 0;
+		$base = WxMiniBaseClass::getById($wxGhsMiniBaseId);
+		if (empty($base)) {
+			util::fail('没有找到平台小程序信息');
+		}
+		return $base;
+	}
+	
+	public static function getGhsWxInfo()
+	{
+		$mini = self::getGhsWxMiniBase();
+		$wx = self::getGhsWxBase();
+		return array_merge($wx, $mini);
+	}
+	
 }

+ 2 - 5
common/components/wxUtil.php

@@ -1631,10 +1631,8 @@ class wxUtil
 	 * 微信开放平台使用授权码换取公众号的接口调用凭据和授权信息
 	 * authorizer_access_token authorizer_refresh_token
 	 */
-	public static function getAuthorizer($code)
+	public static function getAuthorizer($code,$open)
 	{
-		$id = configDict::getConfig('openId');
-		$open = xhWxOpenService::getById($id);
 		$appId = $open['appId'];
 		$accessToken = self::getComponentAccessToken($open);
 		$url = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token={$accessToken}";
@@ -1646,9 +1644,8 @@ class wxUtil
 	}
 	
 	//微信开放平台获取授权方的公众号帐号基本信息 shish 2020.3.11
-	public static function getAuthorizerInfo($authorizeAppId)
+	public static function getAuthorizerInfo($authorizeAppId,$open)
 	{
-		$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}";

+ 6 - 2
console/controllers/UpgradeController.php

@@ -1607,13 +1607,17 @@ UPDATE `xhUserAsset` SET `member`=0 WHERE `member`=-1;";
 	{
 		UserService::syncAvatar($id);
 	}
-	
+
 	//更新公众号的头像和二维码 shish 2020.3.11
 	public function actionUpdateImg($id)
 	{
 		$merchant = MerchantService::getMerchantById($id);
 		$appId = $merchant['wxAppId'];
-		$respond = wxUtil::getAuthorizerInfo($appId);
+		$open = [];
+		if (empty($open)) {
+			util::fail('请确认平台类型');
+		}
+		$respond = wxUtil::getAuthorizerInfo($appId, $open);
 		$update = [];
 		if (isset($respond['authorizer_info']['head_img']) && !empty($respond['authorizer_info']['head_img'])) {
 			$imgUrl = $respond['authorizer_info']['head_img'];