Showing
1 changed file
with
40 additions
and
42 deletions
@@ -708,8 +708,8 @@ class Yohobuy | @@ -708,8 +708,8 @@ class Yohobuy | ||
708 | return false; | 708 | return false; |
709 | } | 709 | } |
710 | 710 | ||
711 | - UdpLog::debug('read memcache'); | ||
712 | 711 | ||
712 | + UdpLog::debug('read memcache'); | ||
713 | $interfaceShunt = Cache::getBy('INTERFACE_SHUT_KEY', 'master'); | 713 | $interfaceShunt = Cache::getBy('INTERFACE_SHUT_KEY', 'master'); |
714 | 714 | ||
715 | UdpLog::debug('read memcahe: ', $interfaceShunt); | 715 | UdpLog::debug('read memcahe: ', $interfaceShunt); |
@@ -719,77 +719,75 @@ class Yohobuy | @@ -719,77 +719,75 @@ class Yohobuy | ||
719 | 719 | ||
720 | $interfaceShunt = json_decode($interfaceShunt, true); | 720 | $interfaceShunt = json_decode($interfaceShunt, true); |
721 | 721 | ||
722 | - $uid = 0; | ||
723 | - $mod = 0; | ||
724 | - | ||
725 | - if (isset($param['uid'])) { | ||
726 | - $uid = intval($param['uid']); | ||
727 | - $mod = $uid % 1024; | ||
728 | - } | ||
729 | - | ||
730 | - if ($mod > 128 || $uid === 0) { | ||
731 | - | ||
732 | - $paseUrl = parse_url($url); | ||
733 | - | ||
734 | - if (strpos($url, 'api')) { | ||
735 | - | ||
736 | - if (empty($interfaceShunt['aws']) || empty($interfaceShunt['aws']['api.yoho.cn'])) { | 722 | + if (empty($interfaceShunt['cloud'])) { |
737 | return false; | 723 | return false; |
738 | } | 724 | } |
739 | 725 | ||
740 | - $num = array_rand($interfaceShunt['aws']['api.yoho.cn']); | 726 | + $uid = isset($param['uid']) ? intval($param['uid']) : 0; |
727 | + $mod = 0; | ||
728 | + $cloud = intval($interfaceShunt['cloud']); | ||
729 | + $ips = ''; | ||
741 | 730 | ||
742 | - if (empty($interfaceShunt['aws']['api.yoho.cn'][$num]['ip'])) { | ||
743 | - return false; | 731 | + switch ($cloud) { |
732 | + case 1: | ||
733 | + $ips = $interfaceShunt['aws']; | ||
734 | + break; | ||
735 | + case 2: | ||
736 | + $ips = $interfaceShunt['tencent']; | ||
737 | + break; | ||
738 | + case 3: | ||
739 | + if (empty($uid) || empty($interfaceShunt['strategy']) || | ||
740 | + empty($interfaceShunt['strategy']['model']) || | ||
741 | + empty($interfaceShunt['strategy']['tencentMax'])) { | ||
742 | + break; | ||
743 | + } else { | ||
744 | + $ips = $uid % $interfaceShunt['strategy']['model'] > $interfaceShunt['strategy']['tencentMax'] ? | ||
745 | + $interfaceShunt['aws'] : $interfaceShunt['tencent']; | ||
744 | } | 746 | } |
745 | - | ||
746 | - $url = 'http://' . $interfaceShunt['aws']['api.yoho.cn'][$num]['ip'] . rtrim($paseUrl['path'], '/') . '/'; | ||
747 | - | ||
748 | - } else if (strpos($url, 'service')) { | ||
749 | - | ||
750 | - if (empty($interfaceShunt['aws']) || empty($interfaceShunt['aws']['service.yoho.cn'])) { | ||
751 | - return false; | 747 | + break; |
748 | + default: | ||
749 | + $ips = ''; | ||
750 | + break; | ||
752 | } | 751 | } |
753 | 752 | ||
754 | - $num = array_rand($interfaceShunt['aws']['service.yoho.cn']); | ||
755 | - | ||
756 | - if (empty($interfaceShunt['aws']['service.yoho.cn'][$num]['ip'])) { | ||
757 | - return false; | 753 | + //未登录情况下 |
754 | + if (empty($uid) && empty($ips) && !empty($interfaceShunt['strategy'] && | ||
755 | + !empty($interfaceShunt['strategy']['notLogin'])) { | ||
756 | + $ips = $interfaceShunt[$interfaceShunt['strategy']['notLogin']]; | ||
758 | } | 757 | } |
759 | 758 | ||
760 | - $url = 'http://' . $interfaceShunt['aws']['service.yoho.cn'][$num]['ip'] . rtrim($paseUrl['path'], '/') . '/'; | 759 | + if (empty($ips)) { |
760 | + return false; | ||
761 | } | 761 | } |
762 | - } else { | ||
763 | 762 | ||
764 | $paseUrl = parse_url($url); | 763 | $paseUrl = parse_url($url); |
765 | - | ||
766 | if (strpos($url, 'api')) { | 764 | if (strpos($url, 'api')) { |
767 | 765 | ||
768 | - if (empty($interfaceShunt['tencent']) || empty($interfaceShunt['tencent']['api.yoho.cn'])) { | 766 | + if (empty($ips['api.yoho.cn'])) { |
769 | return false; | 767 | return false; |
770 | } | 768 | } |
771 | 769 | ||
772 | - $num = array_rand($interfaceShunt['tencent']['api.yoho.cn']); | 770 | + $num = array_rand($ips['api.yoho.cn']); |
773 | 771 | ||
774 | - if (empty($interfaceShunt['tencent']['api.yoho.cn'][$num]['ip'])) { | 772 | + if (empty($ips['api.yoho.cn'][$num]['ip'])) { |
775 | return false; | 773 | return false; |
776 | } | 774 | } |
777 | 775 | ||
778 | - $url = 'http://' . $interfaceShunt['tencent']['api.yoho.cn'][$num]['ip'] . rtrim($paseUrl['path'], '/') . '/'; | 776 | + $url = 'http://' . $ips['api.yoho.cn'][$num]['ip'] . rtrim($paseUrl['path'], '/') . '/'; |
777 | + | ||
779 | } else if (strpos($url, 'service')) { | 778 | } else if (strpos($url, 'service')) { |
780 | 779 | ||
781 | - if (empty($interfaceShunt['tencent']) || empty($interfaceShunt['tencent']['service.yoho.cn'])) { | 780 | + if (empty($ips['service.yoho.cn'])) { |
782 | return false; | 781 | return false; |
783 | } | 782 | } |
784 | 783 | ||
785 | - $num = array_rand($interfaceShunt['tencent']['service.yoho.cn']); | 784 | + $num = array_rand($ips['service.yoho.cn']); |
786 | 785 | ||
787 | - if (empty($interfaceShunt['tencent']['service.yoho.cn'][$num]['ip'])) { | 786 | + if (empty($ips['service.yoho.cn'][$num]['ip'])) { |
788 | return false; | 787 | return false; |
789 | } | 788 | } |
790 | 789 | ||
791 | - $url = 'http://' . $interfaceShunt['tencent']['service.yoho.cn'][$num]['ip'] . rtrim($paseUrl['path'], '/') . '/'; | ||
792 | - } | 790 | + $url = 'http://' . $ips['service.yoho.cn'][$num]['ip'] . rtrim($paseUrl['path'], '/') . '/'; |
793 | } | 791 | } |
794 | 792 | ||
795 | return $url; | 793 | return $url; |
-
Please register or login to post a comment