You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong/app/api/controller/Wxserver.php

112 lines
4.3 KiB

8 months ago
<?php
8 months ago
declare (strict_types=1);
8 months ago
namespace app\api\controller;
7 months ago
use app\common\library\wxserver\Server;
8 months ago
use app\common\model\WxserverAccount;
8 months ago
use cores\BaseController;
8 months ago
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
7 months ago
use think\response\Json;
8 months ago
8 months ago
class Wxserver extends BaseController
8 months ago
{
8 months ago
7 months ago
public function index(): Json
8 months ago
{
7 months ago
$appid = ['wxd87b1a7332d974d0', 'wxe3ed157849bd07b5', 'wx896520d9d03f108f', 'wx35f6c598106b9149', 'wx3f8c109fa934324f'];
$obj = new Server();
$data = $obj->applySetOrderPathInfo($appid);
return $this->renderSuccess(['result' => $data]);
8 months ago
}
8 months ago
8 months ago
public function verifyTicket()
{
8 months ago
$xmlData = file_get_contents("php://input");
7 months ago
$obj = new Server();
8 months ago
$obj->getVerifyTicket($xmlData);
8 months ago
echo 'success';
}
8 months ago
8 months ago
/**
* @notes:授权回调
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
8 months ago
public function redirect()
{
8 months ago
$authorization_code = $this->request->get('auth_code');
8 months ago
if ($authorization_code) {
7 months ago
$obj = new Server();
8 months ago
$obj->authorizationInfo($authorization_code, $this->request->domain(true));
8 months ago
}
8 months ago
echo 'success';
8 months ago
}
8 months ago
8 months ago
public function callback($appid)
8 months ago
{
8 months ago
$time = date('Y-m-d H:i:s');
7 months ago
$obj = new Server();
8 months ago
$signature = $this->request->get('signature');
$timestamp = $this->request->get('timestamp');
$nonce = $this->request->get('nonce');
if ($signature && $timestamp && $nonce) {
if ($obj->checkSignature($signature, $timestamp, $nonce)) {
8 months ago
$xmlData = file_get_contents("php://input");
if ($xmlData) {
$data = $obj->decryptXml($xmlData);
if (!empty($data['MsgType'])) {
if ($data['MsgType'] == 'event' && !empty($data['Event'])) {
$up = [];
if ($data['Event'] == 'weapp_audit_success') {
$up['audit_status'] = 2;
8 months ago
$obj->release($appid);//审核通过发布版本
8 months ago
} elseif ($data['Event'] == 'weapp_audit_fail') {
$up['audit_status'] = 3;
} elseif ($data['Event'] == 'weapp_audit_delay') {
$up['audit_status'] = 4;
}
if (!empty($data['Reason'])) {
$up['audit_reason'] = $data['Reason'];
}
if ($up && $appid) {
$model = new WxserverAccount();
$model->update($up, ['appid' => $appid]);
}
echo 'success';
} elseif ($data['MsgType'] == 'text' && !empty($data['Content'])) {
if ($data['Content'] == 'TESTCOMPONENT_MSG_TYPE_TEXT') {
$data['Content'] = 'TESTCOMPONENT_MSG_TYPE_TEXT_callback';
} elseif (strpos($data['Content'], 'QUERY_AUTH_CODE:') !== false) {
$query_auth_code = trim(str_replace("QUERY_AUTH_CODE:", "", $data['Content']));
$obj->apiText($query_auth_code, $data['FromUserName']);
}
7 months ago
echo $this->responseText($data);
8 months ago
}
8 months ago
}
}
}
}
8 months ago
}
8 months ago
private function responseText($data): string
{
$template = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Content><![CDATA[%s]]></Content>
</xml>";
$fromUser = $data['ToUserName'];
$toUser = $data['FromUserName'];
7 months ago
$content = !empty($data['Content']) ? $data['Content'] : 'success';
8 months ago
$time = time();
$msgType = 'text';
return sprintf($template, $toUser, $fromUser, $time, $msgType, $content);
}
8 months ago
}