AuthService.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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)
  48. {
  49. $dadaAuth = new \common\components\delivery\platform\dada\Auth();
  50. $ticket = $dadaAuth->getTicket();
  51. $redirectUrl = Yii::$app->params['ghsHost'] . '/delivery/dada-auth-callback' . '?mainId=' . $mainId;
  52. $shopNumber = '40d8391f9b05477b';
  53. $state = 'huidiao_biaoshi';
  54. $authUrl = $dadaAuth->generateAuthUrl($ticket, $state, $shopNumber);
  55. //header('Location: ' . $authUrl);
  56. util::success(['url'=>$authUrl]);
  57. }
  58. public function shunfengAuth($mainId)
  59. {
  60. $shunfengAuth = new \common\components\delivery\platform\shunfeng\Auth();
  61. $authUrl = $shunfengAuth->generateAuthUrl($mainId);
  62. util::success(['url'=>$authUrl]);
  63. }
  64. public function didiAuth($mainId, $shopId)
  65. {
  66. // $shop = ShopClass::getById($shopId, false, 'id,lat,long');
  67. // if(!$shop){
  68. // util::fail('门店不存在');
  69. // }
  70. // $lat = $shop['lat'];
  71. // $lng = $shop['long'];
  72. // if(empty($lat) || empty($lng)){
  73. // util::fail('门店经纬度不存在');
  74. // }
  75. $didiAuth = new \common\components\delivery\platform\didi\Auth();
  76. $authUrl = $didiAuth->getAuthUrl($mainId, 110100, '', '');
  77. util::success(['url'=>$authUrl]);
  78. }
  79. }