- 更新微信公众平台的分享接口

v6 v6.0.111
李光春 4 years ago
parent b3cd764516
commit 25b5d7e4db

@ -1,3 +1,6 @@
## v6.0.111 / 2020-09-08
- 更新微信公众平台的分享接口
## v6.0.110 / 2020-09-06 ## v6.0.110 / 2020-09-06
- 更新拼多多 多客接口 - 更新拼多多 多客接口

@ -115,7 +115,7 @@ class ApiController extends stdClass
* @param string $name 参数名 * @param string $name 参数名
* @return $this * @return $this
*/ */
public function setAesMd5($name = 'sniff_h5') public function setAesMd5($name = 'sniff_h5'): self
{ {
$value = config("dtapp.md5.{$name}"); $value = config("dtapp.md5.{$name}");
$this->aes_md5 = $value; $this->aes_md5 = $value;
@ -126,7 +126,7 @@ class ApiController extends stdClass
* iv * iv
* @return $this * @return $this
*/ */
private function setAesMd5Iv() private function setAesMd5Iv(): self
{ {
$value = config("dtapp.md5.bcw"); $value = config("dtapp.md5.bcw");
$this->aes_md5_iv = $value; $this->aes_md5_iv = $value;
@ -169,7 +169,7 @@ class ApiController extends stdClass
* @param mixed $two 回调引用参数2 * @param mixed $two 回调引用参数2
* @return boolean * @return boolean
*/ */
public function callback($name, &$one = [], &$two = []) public function callback($name, &$one = [], &$two = []): bool
{ {
if (is_callable($name)) { if (is_callable($name)) {
return call_user_func($name, $this, $one, $two); return call_user_func($name, $this, $one, $two);

@ -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')) { if (!function_exists('get_ip_info')) {
/** /**

@ -109,7 +109,7 @@ class WebAppService extends Service
* @param string $appId * @param string $appId
* @return $this * @return $this
*/ */
public function appId(string $appId) public function appId(string $appId): self
{ {
$this->app_id = $appId; $this->app_id = $appId;
return $this; return $this;
@ -120,7 +120,7 @@ class WebAppService extends Service
* @param string $appSecret * @param string $appSecret
* @return $this * @return $this
*/ */
public function appSecret(string $appSecret) public function appSecret(string $appSecret): self
{ {
$this->app_secret = $appSecret; $this->app_secret = $appSecret;
return $this; return $this;
@ -130,7 +130,7 @@ class WebAppService extends Service
* 获取配置信息 * 获取配置信息
* @return $this * @return $this
*/ */
private function getConfig() private function getConfig(): self
{ {
$this->cache = config('dtapp.wechat.webapp.cache'); $this->cache = config('dtapp.wechat.webapp.cache');
$this->app_id = config('dtapp.wechat.webapp.app_id'); $this->app_id = config('dtapp.wechat.webapp.app_id');
@ -159,7 +159,7 @@ class WebAppService extends Service
* @return $this * @return $this
* @throws DtaException * @throws DtaException
*/ */
public function scope(string $scope) public function scope(string $scope): self
{ {
if ($scope === "snsapi_base") { if ($scope === "snsapi_base") {
$this->scope = $scope; $this->scope = $scope;
@ -176,7 +176,7 @@ class WebAppService extends Service
* @param string $state * @param string $state
* @return $this * @return $this
*/ */
public function state(string $state) public function state(string $state): self
{ {
$this->state = $state; $this->state = $state;
return $this; return $this;
@ -187,7 +187,7 @@ class WebAppService extends Service
* @param string $cache * @param string $cache
* @return $this * @return $this
*/ */
public function cache(string $cache) public function cache(string $cache): self
{ {
$this->cache = $cache; $this->cache = $cache;
return $this; return $this;
@ -298,11 +298,12 @@ class WebAppService extends Service
/** /**
* 分享 * 分享
* @param string $url
* @return array * @return array
* @throws DbException * @throws DbException
* @throws DtaException * @throws DtaException
*/ */
public function share() public function share($url = '')
{ {
if (empty($this->app_id)) { if (empty($this->app_id)) {
$this->getConfig(); $this->getConfig();
@ -331,9 +332,11 @@ class WebAppService extends Service
throw new DtaException('accessToken已过期'); throw new DtaException('accessToken已过期');
} }
} }
// 注意 URL 一定要动态获取,不能 hardcode. if (empty($url)) {
$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; // 注意 URL 一定要动态获取,不能 hardcode.
$url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] === 443) ? "https://" : "http://";
$url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
}
$timestamp = time(); $timestamp = time();
$nonceStr = $this->createNonceStr(); $nonceStr = $this->createNonceStr();
// 获得jsapi_ticket之后就可以生成JS-SDK权限验证的签名了。 // 获得jsapi_ticket之后就可以生成JS-SDK权限验证的签名了。
@ -350,6 +353,11 @@ class WebAppService extends Service
]; ];
} }
/**
* @param int $length
* @return string
* @throws \Exception
*/
private function createNonceStr($length = 16) private function createNonceStr($length = 16)
{ {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
@ -610,7 +618,7 @@ class WebAppService extends Service
} }
$this->grant_type = "client_credential"; $this->grant_type = "client_credential";
if ($this->cache == "file") { if ($this->cache === "file") {
// 文件名 // 文件名
$file = "{$this->app->getRootPath()}runtime/{$this->app_id}_access_token.json"; $file = "{$this->app->getRootPath()}runtime/{$this->app_id}_access_token.json";
// 获取数据 // 获取数据
@ -669,7 +677,7 @@ class WebAppService extends Service
return $accessToken; return $accessToken;
} }
if ($this->cache == "mysql") { if ($this->cache === "mysql") {
$access_token = []; $access_token = [];
// 文件名 // 文件名
$file = "{$this->app_id}_access_token"; $file = "{$this->app_id}_access_token";

Loading…
Cancel
Save