AuthService.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. //$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. //$apiHost = 'https://api.shop.hzghd.com'; // 暂时修改为测试环境
  30. $redirectUrl = $apiHost . '/delivery/huolala-auth-callback' . '?mainId=' . $mainId;
  31. $authUrl = $huoLalaAuth->generateAuthUrl($redirectUrl);
  32. //header('Location: ' . $authUrl);
  33. util::success(['url'=>$authUrl]);
  34. }
  35. public function fengniaoAuth($mainId)
  36. {
  37. $fengnaioAuth = new \common\components\delivery\platform\fengniao\Auth();
  38. $apiHost = Yii::$app->params['ghsHost'];
  39. //$apiHost = 'https://api.shop.hzghd.com'; // 暂时修改为测试环境
  40. $redirectUrl = $apiHost . '/delivery/fengniao-auth-callback' . '?main_id=' . $mainId;
  41. $authUrl = $fengnaioAuth->generateAuthUrl($redirectUrl);
  42. util::success(['url'=>$authUrl]);
  43. }
  44. public function dadaAuth($mainId, $shopId)
  45. {
  46. $dadaAuth = new \common\components\delivery\platform\dada\Auth($mainId);
  47. $ticket = $dadaAuth->getTicket();
  48. $state = 'huidiao_biaoshi';
  49. $authUrl = $dadaAuth->generateAuthUrl($ticket, $state, $shopId);
  50. //header('Location: ' . $authUrl);
  51. util::success(['url'=>$authUrl]);
  52. }
  53. public function shunfengAuth($mainId)
  54. {
  55. $shunfengAuth = new \common\components\delivery\platform\shunfeng\Auth();
  56. $authUrl = $shunfengAuth->generateAuthUrl($mainId);
  57. util::success(['url'=>$authUrl]);
  58. }
  59. public function didiAuth($mainId, $shopId)
  60. {
  61. $shop = ShopClass::getById($shopId, false, 'id,lat,long');
  62. if(!$shop){
  63. util::fail('门店不存在');
  64. }
  65. $lat = $shop['lat'];
  66. $lng = $shop['long'];
  67. if(empty($lat) || empty($lng)){
  68. util::fail('门店经纬度不存在');
  69. }
  70. $didiAuth = new \common\components\delivery\platform\didi\Auth();
  71. $ret = $didiAuth->getAuthUrl($mainId, '', $lat, $lng);
  72. if(isset($ret['raw']) && $ret['raw']['code'] == 200){
  73. util::success(['url'=>$ret['raw']['data']['authUrl']]);
  74. }else{
  75. Yii::error('滴滴获取授权地址失败:' . json_encode($ret));
  76. util::fail('获取授权地址失败');
  77. }
  78. }
  79. }