AuthService.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace common\components\delivery\services;
  3. use Yii;
  4. use bizHd\shop\classes\ShopClass;
  5. use common\components\util;
  6. Class AuthService{
  7. // ------------------ 授权(账号绑定) ---------------------
  8. //授权
  9. public function shansongAuth($mainId)
  10. {
  11. //闪送授权(商户授权:授权后能为商户下所有门店发单)
  12. $auth = new \common\components\delivery\platform\shansong\Auth();
  13. if(getenv('YII_ENV') == 'production') {
  14. $apiHost = Yii::$app->params['ghsHost'];
  15. // TODO 暂时修改为测试环境
  16. //$apiHost = 'https://api.shop.hzghd.com';
  17. } else {
  18. $apiHost = Yii::$app->params['ghsHost'];
  19. }
  20. $redirectUrl = $apiHost . '/delivery/shansong-auth-callback';
  21. $authUrl = $auth->generateMerchantAuthUrl($mainId, $redirectUrl);
  22. // 重定向用户
  23. //header('Location: ' . $authUrl);
  24. util::success(['url'=>$authUrl]);
  25. }
  26. public function huolalaAuth($mainId)
  27. {
  28. $huoLalaAuth = new \common\components\delivery\platform\huolala\Auth();
  29. $apiHost = Yii::$app->params['ghsHost'];
  30. // TODO 暂时修改为测试环境
  31. //$apiHost = 'https://api.shop.hzghd.com';
  32. $redirectUrl = $apiHost . '/delivery/huolala-auth-callback' . '?mainId=' . $mainId;
  33. $authUrl = $huoLalaAuth->generateAuthUrl($redirectUrl);
  34. //header('Location: ' . $authUrl);
  35. util::success(['url'=>$authUrl]);
  36. }
  37. public function fengniaoAuth($mainId)
  38. {
  39. $fengnaioAuth = new \common\components\delivery\platform\fengniao\Auth();
  40. $apiHost = Yii::$app->params['ghsHost'];
  41. // TODO 暂时修改为测试环境
  42. //$apiHost = 'https://api.shop.hzghd.com';
  43. $redirectUrl = $apiHost . '/delivery/fengniao-auth-callback' . '?main_id=' . $mainId;
  44. $authUrl = $fengnaioAuth->generateAuthUrl($redirectUrl);
  45. util::success(['url'=>$authUrl]);
  46. }
  47. public function dadaAuth($mainId, $shopId)
  48. {
  49. $dadaAuth = new \common\components\delivery\platform\dada\Auth($mainId);
  50. $ticket = $dadaAuth->getTicket();
  51. $state = 'huidiao_biaoshi';
  52. $authUrl = $dadaAuth->generateAuthUrl($ticket, $state, $shopId);
  53. //header('Location: ' . $authUrl);
  54. util::success(['url'=>$authUrl]);
  55. }
  56. public function shunfengAuth($mainId)
  57. {
  58. $shunfengAuth = new \common\components\delivery\platform\shunfeng\Auth();
  59. $authUrl = $shunfengAuth->generateAuthUrl($mainId);
  60. util::success(['url'=>$authUrl]);
  61. }
  62. public function didiAuth($mainId, $shopId)
  63. {
  64. // $shop = ShopClass::getById($shopId, false, 'id,lat,long');
  65. // if(!$shop){
  66. // util::fail('门店不存在');
  67. // }
  68. // $lat = $shop['lat'];
  69. // $lng = $shop['long'];
  70. // if(empty($lat) || empty($lng)){
  71. // util::fail('门店经纬度不存在');
  72. // }
  73. $didiAuth = new \common\components\delivery\platform\didi\Auth();
  74. $authUrl = $didiAuth->getAuthUrl($mainId, 110100, '', '');
  75. util::success(['url'=>$authUrl]);
  76. }
  77. }