|
|
@@ -38,11 +38,6 @@ class WxOpenController extends PublicController
|
|
|
//设置预授码过期,让下个用户可以获取新的预授码
|
|
|
xhWxOpenService::updateById($id, $oData);
|
|
|
$url = Yii::$app->params['wHost'] . '/wx-open/callback';
|
|
|
- $merchantId = $open['merchantId'];
|
|
|
- //如果平台没有对应的商家,先去创建第一个商家并做关联
|
|
|
- if (empty($merchantId)) {
|
|
|
- $url = Yii::$app->params['wHost'] . '/wx-open/callback-create-first-merchant';
|
|
|
- }
|
|
|
echo "<a href='https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid={$appId}&pre_auth_code={$pre}&redirect_uri={$url}'>授权</a>";
|
|
|
}
|
|
|
|
|
|
@@ -70,7 +65,7 @@ class WxOpenController extends PublicController
|
|
|
}
|
|
|
util::fail();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//创建平台使用的公众号
|
|
|
public function actionCallbackCreateFirstMerchant()
|
|
|
{
|
|
|
@@ -113,97 +108,9 @@ class WxOpenController extends PublicController
|
|
|
$merchant = xhMerchantService::getByAppId($authorizeAppId);
|
|
|
$wxAccessTokenTime = date("Y-m-d H:i:s", (time() + $expires_in - 100));//安全起见,将过期时间设置得比微信里还短100秒
|
|
|
if (!empty($merchant)) {
|
|
|
- util::stop('此公众号已经授权过了');
|
|
|
- }
|
|
|
- //引导生成商家
|
|
|
- $date = date("Y-m-d H:i:s");
|
|
|
- $trainDemo = configDict::getConfig('trainDemo');
|
|
|
- //$logo = xhMerchantService::logoSave($head_img, $authorizeAppId);
|
|
|
- $logo = '';
|
|
|
- $appData['logo'] = $logo;
|
|
|
- //保存公众号二维码
|
|
|
- //$wxQrCodeUrl = xhMerchantService::qrCodeSave($qrCodeUrl, $authorizeAppId);
|
|
|
- $wxQrCodeUrl = '';
|
|
|
- $appData['wxQrcodeUrl'] = $wxQrCodeUrl;
|
|
|
- $appData['wxAppId'] = $authorizeAppId;
|
|
|
- $appData['wxUserName'] = $user_name;
|
|
|
- $appData['wxAliasName'] = $alias;
|
|
|
- $appData['wxAccessToken'] = $authorize_access_token;
|
|
|
- $appData['wxAccessTokenTime'] = $wxAccessTokenTime;
|
|
|
- $appData['wxRefreshToken'] = $authorize_refresh_token;
|
|
|
- $appData['accountStyle'] = 0;//认证服务号
|
|
|
- $appData['status'] = 0;//待审核
|
|
|
- $appData['createTime'] = $date;
|
|
|
- $appData['updateTime'] = $date;
|
|
|
- $appData['shopLat'] = (string)0;
|
|
|
- $appData['shopLong'] = (string)0;
|
|
|
- $appData['shopPrecision'] = (string)0;
|
|
|
- $appData['account'] = $trainDemo['platform']['account'];
|
|
|
- $appData['adminId'] = 0;
|
|
|
- $appData['wxToken'] = stringUtil::buildWxToken(0);
|
|
|
- $appData['shopPhotoList'] = '';
|
|
|
- $appData['merchantName'] = $nick_name;
|
|
|
- $appData['shopProvince'] = '福建';
|
|
|
- $appData['shopCity'] = '厦门';
|
|
|
- $appData['shopDist'] = '思明区';
|
|
|
- $appData['alipayAccount'] = 'shish@zhhinc.com';
|
|
|
- $appData['alipayAccountName'] = '石少华';
|
|
|
- $appData['agentLevel'] = 1;//默认设置为代理商
|
|
|
- $merchant = xhMerchantService::applyCreateMerchant($appData);
|
|
|
- $wxOpenId = configDict::getConfig('openId');
|
|
|
- $merchantId = $merchant['id'];
|
|
|
- xhWxOpenService::updateById($wxOpenId, ['merchantId' => $merchantId]);
|
|
|
-
|
|
|
- $data = ['merchantId'=>$merchantId,'platform'=>1];
|
|
|
- $producer = Yii::$app->rabbitmq->getProducer('openShopInitProducer');
|
|
|
- $msg = serialize($data);
|
|
|
- $producer->publish($msg, 'openShopInitExchange', 'openShopInitRoute');
|
|
|
-
|
|
|
- echo 'ok';
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public function actionCallback()
|
|
|
- {
|
|
|
- $get = Yii::$app->request->get();
|
|
|
- if (isset($get['auth_code']) == false) {
|
|
|
- util::stop('公众号授权回调未成功');
|
|
|
- }
|
|
|
- $code = $get['auth_code'];
|
|
|
- //使用授权码换取公众号的接口调用凭据和授权信息
|
|
|
- $authorize = wxUtil::getAuthorizer($code);
|
|
|
- if (isset($authorize['authorization_info']) == false) {
|
|
|
- util::stop('未换取公众号的接口调用凭据和授权信息');
|
|
|
- }
|
|
|
- $info = $authorize['authorization_info'];
|
|
|
- $authorizeAppId = $info['authorizer_appid'];
|
|
|
- $authorize_access_token = $info['authorizer_access_token'];
|
|
|
- $expires_in = $info['expires_in'];//7200
|
|
|
- $authorize_refresh_token = $info['authorizer_refresh_token'];
|
|
|
- //获取授权方的基本信息
|
|
|
- $authorizeDetailInfo = wxUtil::getAuthorizerInfo($authorizeAppId);
|
|
|
- if (isset($authorizeDetailInfo['authorizer_info']) == false) {
|
|
|
- util::stop('没有获取到公众号帐号基本信息');
|
|
|
- }
|
|
|
- $authorize_info = $authorizeDetailInfo['authorizer_info'];
|
|
|
- $nick_name = $authorize_info['nick_name'];
|
|
|
- $head_img = $authorize_info['head_img'];
|
|
|
- $service_type_info = $authorize_info['service_type_info'];
|
|
|
- if (isset($authorize_info['MiniProgramInfo']) == false || empty($authorize_info['MiniProgramInfo'])) {
|
|
|
- if ($service_type_info['id'] != 2) {
|
|
|
- util::stop('公众号不是服务号,appId:' . $authorizeAppId . ' refresh:' . $authorize_refresh_token);
|
|
|
- }
|
|
|
+ util::stop('此公众号或小程序已经授权过了');
|
|
|
}
|
|
|
- $verify_type_info = $authorize_info['verify_type_info'];
|
|
|
- if ($verify_type_info['id'] != 0) {
|
|
|
- util::stop('公众号还没有认证哦');
|
|
|
- }
|
|
|
- $user_name = $authorize_info['user_name'];
|
|
|
- $alias = $authorize_info['alias'];
|
|
|
- $qrCodeUrl = $authorize_info['qrcode_url'];
|
|
|
- $business_info = $authorize_info['business_info'];
|
|
|
- $open_pay = $business_info['open_pay'];
|
|
|
- $accessTokenTime = date("Y-m-d H:i:s", (time() + $expires_in - 100));//安全起见,将过期时间设置得比微信里还短100秒
|
|
|
+
|
|
|
//小程序
|
|
|
if (isset($authorize_info['MiniProgramInfo']) && !empty($authorize_info['MiniProgramInfo'])) {
|
|
|
$merchant = xhMerchantService::getByCondition(['miniAppId' => $authorizeAppId]);
|
|
|
@@ -215,34 +122,69 @@ class WxOpenController extends PublicController
|
|
|
xhMerchantExtendService::updateByMerchantId($merchantId, ['miniAccessToken' => $authorize_access_token, 'miniAccessTokenTime' => $accessTokenTime, 'miniRefreshToken' => $authorize_refresh_token]);
|
|
|
Yii::info('小程序信息更新成功:' . json_encode($authorize_info));
|
|
|
util::stop("小程序信息更新成功");
|
|
|
- } else {
|
|
|
- $merchant = xhMerchantService::getByAppId($authorizeAppId);
|
|
|
- Yii::info('appId:' . $authorizeAppId);
|
|
|
- $set = xhSetMealService::getRandOne();
|
|
|
- if (empty($set)) {
|
|
|
- util::stop('没有套餐信息');
|
|
|
- }
|
|
|
- if (empty($merchant)) {
|
|
|
- util::stop('这个商家没有生成过基本信息。appid:' . $authorizeAppId);
|
|
|
- }
|
|
|
- if (empty($merchant)) {
|
|
|
- echo '新建商家能力暂时关闭';
|
|
|
- Yii::$app->end();
|
|
|
- //没有生成商家,引导进去设置
|
|
|
- $session = Yii::$app->session;
|
|
|
- $session['wxAppId'] = $authorizeAppId;
|
|
|
- $session['wxUserName'] = $user_name;
|
|
|
- $session['wxAliasName'] = $alias;
|
|
|
- $session['wxAccessToken'] = $authorize_access_token;
|
|
|
- $session['wxAccessTokenTime'] = $accessTokenTime;
|
|
|
- $session['wxRefreshToken'] = $authorize_refresh_token;
|
|
|
- $session['logo'] = $head_img;
|
|
|
- $session['wxQrcodeUrl'] = $qrCodeUrl;
|
|
|
- $session['allowGenerateMerchant'] = 'ok';//经过授权流程,允许允许生成商家
|
|
|
- $trainDemo = configDict::getConfig('trainDemo');
|
|
|
- $demoName = $trainDemo['merchant']['name'];//培训演示的公众号
|
|
|
- return $this->renderPartial('callback', ['merchantName' => $nick_name, 'set' => $set, 'demoName' => $demoName]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $merchant = xhMerchantService::getByAppId($authorizeAppId);
|
|
|
+ Yii::info('appId:' . $authorizeAppId);
|
|
|
+ $set = xhSetMealService::getRandOne();
|
|
|
+ if (empty($set)) {
|
|
|
+ util::stop('没有套餐信息');
|
|
|
+ }
|
|
|
+ if (empty($merchant)) {
|
|
|
+ util::stop('这个商家没有生成过基本信息。appid:' . $authorizeAppId);
|
|
|
+ }
|
|
|
+ if (empty($merchant)) {
|
|
|
+
|
|
|
+ //引导生成商家
|
|
|
+ $date = date("Y-m-d H:i:s");
|
|
|
+ $trainDemo = configDict::getConfig('trainDemo');
|
|
|
+ //$logo = xhMerchantService::logoSave($head_img, $authorizeAppId);
|
|
|
+ $logo = '';
|
|
|
+ $appData['logo'] = $logo;
|
|
|
+ //保存公众号二维码
|
|
|
+ //$wxQrCodeUrl = xhMerchantService::qrCodeSave($qrCodeUrl, $authorizeAppId);
|
|
|
+ $wxQrCodeUrl = '';
|
|
|
+ $appData['wxQrcodeUrl'] = $wxQrCodeUrl;
|
|
|
+ $appData['wxAppId'] = $authorizeAppId;
|
|
|
+ $appData['wxUserName'] = $user_name;
|
|
|
+ $appData['wxAliasName'] = $alias;
|
|
|
+ $appData['wxAccessToken'] = $authorize_access_token;
|
|
|
+ $appData['wxAccessTokenTime'] = $wxAccessTokenTime;
|
|
|
+ $appData['wxRefreshToken'] = $authorize_refresh_token;
|
|
|
+ $appData['accountStyle'] = 0;//认证服务号
|
|
|
+ $appData['status'] = 0;//待审核
|
|
|
+ $appData['createTime'] = $date;
|
|
|
+ $appData['updateTime'] = $date;
|
|
|
+ $appData['shopLat'] = (string)0;
|
|
|
+ $appData['shopLong'] = (string)0;
|
|
|
+ $appData['shopPrecision'] = (string)0;
|
|
|
+ $appData['account'] = $trainDemo['platform']['account'];
|
|
|
+ $appData['adminId'] = 0;
|
|
|
+ $appData['wxToken'] = stringUtil::buildWxToken(0);
|
|
|
+ $appData['shopPhotoList'] = '';
|
|
|
+ $appData['merchantName'] = $nick_name;
|
|
|
+ $appData['shopProvince'] = '福建';
|
|
|
+ $appData['shopCity'] = '厦门';
|
|
|
+ $appData['shopDist'] = '思明区';
|
|
|
+ $appData['alipayAccount'] = 'shish@zhhinc.com';
|
|
|
+ $appData['alipayAccountName'] = '石少华';
|
|
|
+ $appData['agentLevel'] = 1;//默认设置为代理商
|
|
|
+ $merchant = xhMerchantService::applyCreateMerchant($appData);
|
|
|
+ $merchantId = $merchant['id'];
|
|
|
+
|
|
|
+ $wxOpenId = configDict::getConfig('openId');
|
|
|
+ $open = xhWxOpenService::getById($wxOpenId);
|
|
|
+ if(isset($open['merchantId']) && !empty($open['merchantId'])){
|
|
|
+ xhWxOpenService::updateById($wxOpenId, ['merchantId' => $merchantId]);
|
|
|
}
|
|
|
+
|
|
|
+ $data = ['merchantId' => $merchantId, 'platform' => 1];
|
|
|
+ $producer = Yii::$app->rabbitmq->getProducer('openShopInitProducer');
|
|
|
+ $msg = serialize($data);
|
|
|
+ $producer->publish($msg, 'openShopInitExchange', 'openShopInitRoute');
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
$cData = [];
|
|
|
$cData['wxAccessToken'] = $authorize_access_token;
|
|
|
$cData['wxAccessTokenTime'] = $accessTokenTime;
|
|
|
@@ -251,11 +193,17 @@ class WxOpenController extends PublicController
|
|
|
$cData['status'] = 1;
|
|
|
$merchantId = $merchant['id'];
|
|
|
xhMerchantService::updateById($merchantId, $cData);
|
|
|
- }
|
|
|
- echo $authorizeAppId . ' ok';
|
|
|
|
|
|
+ }
|
|
|
+ echo 'ok';
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ public function actionCallback()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public function actionResult()
|
|
|
{
|
|
|
$get = Yii::$app->request->get();
|