diff --git a/lib/wxpay/example/WxPay.JsApiPay.php b/lib/wxpay/example/WxPay.JsApiPay.php index 7fccf3aef..8f89fa6e2 100644 --- a/lib/wxpay/example/WxPay.JsApiPay.php +++ b/lib/wxpay/example/WxPay.JsApiPay.php @@ -43,7 +43,9 @@ public function GetOpenid() //通过code获得openid if (!isset($_GET['code'])){ //触发微信返回code码 - $baseUrl = urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; //.$_SERVER['QUERY_STRING']); + $https = Yii::$service->url->isHttps() ? 'https' : 'http'; + $baseUrl = urlencode($https . '://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); // $_SERVER['QUERY_STRING']; + // echo $baseUrl;exit; $url = $this->__CreateOauthUrlForCode($baseUrl); Header("Location: $url"); exit(); diff --git a/services/Url.php b/services/Url.php index e5ba03faf..0f41e8754 100644 --- a/services/Url.php +++ b/services/Url.php @@ -275,6 +275,17 @@ public function homeUrl() { return Yii::$app->getHomeUrl(); } + + public function isHttps() + { + $homeUrl = $this->homeUrl(); + if (substr($homeUrl, 0, 5) == 'https') { + + return true; + } + + return false; + } /** * get base url.