This commit is contained in:
2024-05-07 14:41:14 +08:00
parent de4f58d3e3
commit a3aa8e8ac3
+24 -10
View File
@@ -6,6 +6,27 @@ namespace wchat\wx;
use wchat\common\Result; use wchat\common\Result;
enum Scene
{
case SCENE_INFO;
case SCENE_REPLY;
case SCENE_DISCAZ;
case SCENE_SHEJIAO;
public function getValue(): int
{
return match ($this) {
self::SCENE_INFO => 1,
self::SCENE_REPLY => 2,
self::SCENE_DISCAZ => 3,
self::SCENE_SHEJIAO => 4,
};
}
}
/** /**
* Class SecCheck * Class SecCheck
* @package wchat * @package wchat
@@ -63,20 +84,13 @@ class SecCheck extends SmallProgram
} }
const SCENE_INFO = 1;
const SCENE_REPLY = 2;
const SCENE_DISCAZ = 3;
const SCENE_SHEJIAO = 4;
/** /**
* @param string $content * @param string $content
* @param int $scene * @param int $scene
* @param string $openId * @param string $openId
* @return Result * @return Result
*/ */
public function text(string $content, int $scene, string $openId): Result public function text(string $content, Scene $scene, string $openId): Result
{ {
if (empty($content)) { if (empty($content)) {
return $this->sendError('文件不存在', 404); return $this->sendError('文件不存在', 404);
@@ -86,9 +100,9 @@ class SecCheck extends SmallProgram
return $this->post('api.weixin.qq.com', $requestUrl, json_encode([ return $this->post('api.weixin.qq.com', $requestUrl, json_encode([
'content' => $content, 'content' => $content,
'version' => 2, 'version' => 2,
'scene' => $scene, 'scene' => $scene->getValue(),
'openid' => $openId 'openid' => $openId
], JSON_UNESCAPED_UNICODE),'application/json'); ], JSON_UNESCAPED_UNICODE), 'application/json');
} }
} }