|
@@ -0,0 +1,49 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+
|
|
|
+namespace app\api\controller\hprose\util;
|
|
|
+
|
|
|
+
|
|
|
+use app\common\model\WechatConfig;
|
|
|
+use EasyWeChat\Factory;
|
|
|
+use think\facade\Log;
|
|
|
+
|
|
|
+class WechatMpHelper
|
|
|
+{
|
|
|
+ protected $app = null;
|
|
|
+
|
|
|
+ public $res = ["code" => -1];
|
|
|
+
|
|
|
+ public function __construct($authInfo)
|
|
|
+ {
|
|
|
+ $sign = $authInfo["sign"];
|
|
|
+ $time = $authInfo["time"];
|
|
|
+ $code = $authInfo["code"];
|
|
|
+ $wechatConfig = WechatConfig::getEasyWechatConfig($code);
|
|
|
+ $sign2 = md5($code . $time . $wechatConfig["sign_key"]);
|
|
|
+ if (strtoupper($sign2) != strtoupper($sign)) {
|
|
|
+ $this->res = returnFormat(500, "签名失败", ["sign" => $sign, "sign2" => $sign2]);
|
|
|
+ }
|
|
|
+ $this->app = Factory::officialAccount($wechatConfig);
|
|
|
+
|
|
|
+ $this->res = returnFormat(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送模板消息
|
|
|
+ * @param $data
|
|
|
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
|
|
|
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
|
|
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
|
|
|
+ * @throws \GuzzleHttp\Exception\GuzzleException
|
|
|
+ */
|
|
|
+ public function templateMessageSend($data)
|
|
|
+ {
|
|
|
+
|
|
|
+ $res = $this->app->template_message->send($data);
|
|
|
+
|
|
|
+ $this->res = array_merge($res, returnFormat($res["errcode"], $res["errmsg"]));
|
|
|
+ Log::record(json_encode($this->res, JSON_UNESCAPED_UNICODE), "debug");
|
|
|
+ return $this->res;
|
|
|
+ }
|
|
|
+}
|