AuthService.php 3.2 KB

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