| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace common\components\delivery\services;
- use Yii;
- use bizHd\shop\classes\ShopClass;
- use common\components\util;
- Class AuthService{
- // ------------------ 授权(账号绑定) ---------------------
- //授权
- public function shansongAuth($mainId)
- {
- //闪送授权(商户授权:授权后能为商户下所有门店发单)
- $auth = new \common\components\delivery\platform\shansong\Auth();
- if(getenv('YII_ENV') == 'production') {
- $apiHost = Yii::$app->params['ghsHost'];
- //$apiHost = 'https://api.shop.hzghd.com'; // 修改为测试环境
- } else {
- $apiHost = Yii::$app->params['ghsHost'];
- }
- $redirectUrl = $apiHost . '/delivery/shansong-auth-callback';
- $authUrl = $auth->generateMerchantAuthUrl($mainId, $redirectUrl);
- // 重定向用户
- //header('Location: ' . $authUrl);
- util::success(['url'=>$authUrl]);
- }
- public function huolalaAuth($mainId)
- {
- $huoLalaAuth = new \common\components\delivery\platform\huolala\Auth();
- $apiHost = Yii::$app->params['ghsHost'];
- //$apiHost = 'https://api.shop.hzghd.com'; // 暂时修改为测试环境
- $redirectUrl = $apiHost . '/delivery/huolala-auth-callback' . '?mainId=' . $mainId;
- $authUrl = $huoLalaAuth->generateAuthUrl($redirectUrl);
- //header('Location: ' . $authUrl);
- util::success(['url'=>$authUrl]);
- }
- public function fengniaoAuth($mainId)
- {
- $fengnaioAuth = new \common\components\delivery\platform\fengniao\Auth();
- $apiHost = Yii::$app->params['ghsHost'];
- //$apiHost = 'https://api.shop.hzghd.com'; // 暂时修改为测试环境
- $redirectUrl = $apiHost . '/delivery/fengniao-auth-callback' . '?main_id=' . $mainId;
- $authUrl = $fengnaioAuth->generateAuthUrl($redirectUrl);
- util::success(['url'=>$authUrl]);
- }
- public function dadaAuth($mainId, $shopId)
- {
- $dadaAuth = new \common\components\delivery\platform\dada\Auth($mainId);
- $ticket = $dadaAuth->getTicket();
- $state = 'huidiao_biaoshi';
- $authUrl = $dadaAuth->generateAuthUrl($ticket, $state, $shopId);
- //header('Location: ' . $authUrl);
- util::success(['url'=>$authUrl]);
- }
- public function shunfengAuth($mainId)
- {
- $shunfengAuth = new \common\components\delivery\platform\shunfeng\Auth();
- $authUrl = $shunfengAuth->generateAuthUrl($mainId);
- util::success(['url'=>$authUrl]);
- }
- public function didiAuth($mainId, $shopId)
- {
- $shop = ShopClass::getById($shopId, false, 'id,lat,long');
- if(!$shop){
- util::fail('门店不存在');
- }
- $lat = $shop['lat'];
- $lng = $shop['long'];
- if(empty($lat) || empty($lng)){
- util::fail('门店经纬度不存在');
- }
- $didiAuth = new \common\components\delivery\platform\didi\Auth();
- $ret = $didiAuth->getAuthUrl($mainId, '', $lat, $lng);
- if(isset($ret['raw']) && $ret['raw']['code'] == 200){
- util::success(['url'=>$ret['raw']['data']['authUrl']]);
- }else{
- Yii::error('滴滴获取授权地址失败:' . json_encode($ret));
- util::fail('获取授权地址失败');
- }
- }
- }
|