diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e958e73185f0de9f4c1c0e43598911f7175f0d3..f1e0dc316ee331ba02f8e5952f4450ffc6c5bbaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v6.0.111 / 2020-09-08 +- 更新微信公众平台的分享接口 + ## v6.0.110 / 2020-09-06 - 更新拼多多 多客接口 diff --git a/src/ApiController.php b/src/ApiController.php index 2599403978a899b34f5595529c40ec989bd6cd21..64398f6412d7a32d4b3961677a5659bb407b75a9 100644 --- a/src/ApiController.php +++ b/src/ApiController.php @@ -115,7 +115,7 @@ class ApiController extends stdClass * @param string $name 参数名 * @return $this */ - public function setAesMd5($name = 'sniff_h5') + public function setAesMd5($name = 'sniff_h5'): self { $value = config("dtapp.md5.{$name}"); $this->aes_md5 = $value; @@ -126,7 +126,7 @@ class ApiController extends stdClass * iv * @return $this */ - private function setAesMd5Iv() + private function setAesMd5Iv(): self { $value = config("dtapp.md5.bcw"); $this->aes_md5_iv = $value; @@ -169,7 +169,7 @@ class ApiController extends stdClass * @param mixed $two 回调引用参数2 * @return boolean */ - public function callback($name, &$one = [], &$two = []) + public function callback($name, &$one = [], &$two = []): bool { if (is_callable($name)) { return call_user_func($name, $this, $one, $two); diff --git a/src/common.php b/src/common.php index 1b7ebf59d4ed65080e96ed0f3395d21a86b539fa..cc1aac91d09d90515e8c05048c5c0f99f406c7d2 100644 --- a/src/common.php +++ b/src/common.php @@ -25,7 +25,7 @@ use DtApp\ThinkLibrary\service\SystemService; /** * 定义当前版本 */ -const VERSION = '6.0.110'; +const VERSION = '6.0.111'; if (!function_exists('get_ip_info')) { /** diff --git a/src/service/wechat/WebAppService.php b/src/service/wechat/WebAppService.php index 049e1d215337556d48151f338c6c5d61b41aa4fd..eefa150532351e3c3ccb2d3da9eae88da633c768 100644 --- a/src/service/wechat/WebAppService.php +++ b/src/service/wechat/WebAppService.php @@ -109,7 +109,7 @@ class WebAppService extends Service * @param string $appId * @return $this */ - public function appId(string $appId) + public function appId(string $appId): self { $this->app_id = $appId; return $this; @@ -120,7 +120,7 @@ class WebAppService extends Service * @param string $appSecret * @return $this */ - public function appSecret(string $appSecret) + public function appSecret(string $appSecret): self { $this->app_secret = $appSecret; return $this; @@ -130,7 +130,7 @@ class WebAppService extends Service * 获取配置信息 * @return $this */ - private function getConfig() + private function getConfig(): self { $this->cache = config('dtapp.wechat.webapp.cache'); $this->app_id = config('dtapp.wechat.webapp.app_id'); @@ -159,7 +159,7 @@ class WebAppService extends Service * @return $this * @throws DtaException */ - public function scope(string $scope) + public function scope(string $scope): self { if ($scope === "snsapi_base") { $this->scope = $scope; @@ -176,7 +176,7 @@ class WebAppService extends Service * @param string $state * @return $this */ - public function state(string $state) + public function state(string $state): self { $this->state = $state; return $this; @@ -187,7 +187,7 @@ class WebAppService extends Service * @param string $cache * @return $this */ - public function cache(string $cache) + public function cache(string $cache): self { $this->cache = $cache; return $this; @@ -298,11 +298,12 @@ class WebAppService extends Service /** * 分享 + * @param string $url * @return array * @throws DbException * @throws DtaException */ - public function share() + public function share($url = '') { if (empty($this->app_id)) { $this->getConfig(); @@ -331,9 +332,11 @@ class WebAppService extends Service throw new DtaException('accessToken已过期'); } } - // 注意 URL 一定要动态获取,不能 hardcode. - $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; - $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; + if (empty($url)) { + // 注意 URL 一定要动态获取,不能 hardcode. + $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] === 443) ? "https://" : "http://"; + $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; + } $timestamp = time(); $nonceStr = $this->createNonceStr(); // 获得jsapi_ticket之后,就可以生成JS-SDK权限验证的签名了。 @@ -350,6 +353,11 @@ class WebAppService extends Service ]; } + /** + * @param int $length + * @return string + * @throws \Exception + */ private function createNonceStr($length = 16) { $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; @@ -610,7 +618,7 @@ class WebAppService extends Service } $this->grant_type = "client_credential"; - if ($this->cache == "file") { + if ($this->cache === "file") { // 文件名 $file = "{$this->app->getRootPath()}runtime/{$this->app_id}_access_token.json"; // 获取数据 @@ -669,7 +677,7 @@ class WebAppService extends Service return $accessToken; } - if ($this->cache == "mysql") { + if ($this->cache === "mysql") { $access_token = []; // 文件名 $file = "{$this->app_id}_access_token";