Skip to content

Commit

Permalink
fix: 更新项目配置描述
Browse files Browse the repository at this point in the history
  • Loading branch information
zoujingli committed Sep 20, 2024
1 parent 0e70c7f commit 3fc888a
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 12 deletions.
48 changes: 41 additions & 7 deletions WeChat/Contracts/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,29 @@
use WeChat\Exceptions\InvalidResponseException;
use WeChat\Exceptions\LocalCacheException;

// =====================================================
// 配置缓存处理函数 ( 适配其他环境 )
// -----------------------------------------------------
// 数据缓存 (set|get|del) 操作可以将缓存写到任意位置或Redis
// 文件缓存 (put) 只能写在本地服务器,还需要返回可读的文件路径
// 未配置自定义缓存处理机制时,默认在 cache_path 写入文件缓存
// // =====================================================
// \WeChat\Contracts\Tools::$cache_callable = [
// 'set' => function ($name, $value, $expired = 360) {
// var_dump(func_get_args());
// },
// 'get' => function ($name) {
// var_dump(func_get_args());
// },
// 'del' => function ($name) {
// var_dump(func_get_args());
// },
// 'put' => function ($name) {
// var_dump(func_get_args());
// return $filePath;
// },
// ];

/**
* 网络请求支持
* Class Tools
Expand All @@ -34,14 +57,14 @@ class Tools
public static $cache_path = null;

/**
* 缓存写入操作
* 缓存读写配置
* @var array
*/
public static $cache_callable = [
'set' => null, // 写入缓存
'get' => null, // 获取缓存
'del' => null, // 删除缓存
'put' => null, // 写入文件
'set' => null, // 写入缓存 ($name,$value='',$expired=3600):string
'get' => null, // 获取缓存 ($name):mixed|null
'del' => null, // 删除缓存 ($name):boolean
'put' => null, // 写入文件 ($name,$content):string
];

/**
Expand All @@ -67,7 +90,7 @@ public static function createNoncestr($length = 32, $str = "")

/**
* 获取输入对象
* @return false|mixed|string
* @return string
*/
public static function getRawInput()
{
Expand All @@ -78,6 +101,16 @@ public static function getRawInput()
}
}

/**
* 设置输入内容
* @param string $rawInput
* @return void
*/
public static function setRawInput($rawInput)
{
$GLOBALS['HTTP_RAW_POST_DATA'] = $rawInput;
}

/**
* 根据文件后缀获取文件类型
* @param string|array $ext 文件后缀
Expand Down Expand Up @@ -353,7 +386,8 @@ public static function doRequest($method, $url, $options = [])
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
list($content) = [curl_exec($curl), curl_close($curl)];
$content = curl_exec($curl);
curl_close($curl);
// 清理 CURL 缓存文件
if (!empty(self::$cache_curl)) foreach (self::$cache_curl as $key => $file) {
Tools::delCache($file);
Expand Down
13 changes: 10 additions & 3 deletions _test/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@
// | github 代码仓库:https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------

// 配置缓存处理函数
//\WeChat\Contracts\Tools::$cache_callable = [
// =====================================================
// 配置缓存处理函数 ( 适配其他环境 )
// -----------------------------------------------------
// 数据缓存 (set|get|del) 操作可以将缓存写到任意位置或Redis
// 文件缓存 (put) 只能写在本地服务器,还需要返回可读的文件路径
// 未配置自定义缓存处理机制时,默认在 cache_path 写入文件缓存
// // =====================================================
// \WeChat\Contracts\Tools::$cache_callable = [
// 'set' => function ($name, $value, $expired = 360) {
// var_dump(func_get_args());
// },
Expand All @@ -27,8 +33,9 @@
// },
// 'put' => function ($name) {
// var_dump(func_get_args());
// return $filePath;
// },
//];
// ];

return [
'token' => 'test',
Expand Down
23 changes: 23 additions & 0 deletions _test/pay-v3-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@
// | github 代码仓库:https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------

// =====================================================
// 配置缓存处理函数 ( 适配其他环境 )
// -----------------------------------------------------
// 数据缓存 (set|get|del) 操作可以将缓存写到任意位置或Redis
// 文件缓存 (put) 只能写在本地服务器,还需要返回可读的文件路径
// 未配置自定义缓存处理机制时,默认在 cache_path 写入文件缓存
// // =====================================================
// \WeChat\Contracts\Tools::$cache_callable = [
// 'set' => function ($name, $value, $expired = 360) {
// var_dump(func_get_args());
// },
// 'get' => function ($name) {
// var_dump(func_get_args());
// },
// 'del' => function ($name) {
// var_dump(func_get_args());
// },
// 'put' => function ($name) {
// var_dump(func_get_args());
// return $filePath;
// },
// ];

$certPublic = <<<CERT
-----BEGIN CERTIFICATE-----
你的微信商户证书公钥内容
Expand Down
28 changes: 26 additions & 2 deletions _test/work-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,31 @@
// | github 代码仓库:https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------

// =====================================================
// 配置缓存处理函数 ( 适配其他环境 )
// -----------------------------------------------------
// 数据缓存 (set|get|del) 操作可以将缓存写到任意位置或Redis
// 文件缓存 (put) 只能写在本地服务器,还需要返回可读的文件路径
// 未配置自定义缓存处理机制时,默认在 cache_path 写入文件缓存
// // =====================================================
// \WeChat\Contracts\Tools::$cache_callable = [
// 'set' => function ($name, $value, $expired = 360) {
// var_dump(func_get_args());
// },
// 'get' => function ($name) {
// var_dump(func_get_args());
// },
// 'del' => function ($name) {
// var_dump(func_get_args());
// },
// 'put' => function ($name) {
// var_dump(func_get_args());
// return $filePath;
// },
// ];

return [
'appid' => '', // 企业ID
'appsecret' => '', // 应用的凭证密钥
'appid' => '', // 企业ID
'appsecret' => '', // 应用的凭证密钥
'cache_path' => '', // 配置缓存目录
];
23 changes: 23 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,29 @@ include "您的目录/WeChatDeveloper/include.php";
2.1 接口实例所需参数

```php
// =====================================================
// 配置缓存处理函数 ( 适配其他环境 )
// -----------------------------------------------------
// 数据缓存 (set|get|del) 操作可以将缓存写到任意位置或Redis
// 文件缓存 (put) 只能写在本地服务器,还需要返回可读的文件路径
// 未配置自定义缓存处理机制时,默认在 cache_path 写入文件缓存
// // =====================================================
// \WeChat\Contracts\Tools::$cache_callable = [
// 'set' => function ($name, $value, $expired = 360) {
// var_dump(func_get_args());
// },
// 'get' => function ($name) {
// var_dump(func_get_args());
// },
// 'del' => function ($name) {
// var_dump(func_get_args());
// },
// 'put' => function ($name) {
// var_dump(func_get_args());
// return $filePath;
// },
// ];

$config = [
'token' => 'test',
'appid' => 'wx60a43dd8161666d4',
Expand Down

0 comments on commit 3fc888a

Please sign in to comment.