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.
100 lines
3.9 KiB
100 lines
3.9 KiB
7 months ago
|
<?php
|
||
|
declare (strict_types=1);
|
||
|
|
||
|
namespace app\api\controller;
|
||
|
|
||
|
use app\common\model\WxwholesalerAccount;
|
||
|
use think\db\exception\DataNotFoundException;
|
||
|
use think\db\exception\DbException;
|
||
|
use think\db\exception\ModelNotFoundException;
|
||
|
|
||
|
class Wxwholesaler
|
||
|
{
|
||
|
|
||
|
public function verifyTicket()
|
||
|
{
|
||
|
$xmlData = file_get_contents("php://input");
|
||
|
$obj = new \app\common\library\wxserver\Wholesaler();
|
||
|
$obj->getVerifyTicket($xmlData);
|
||
|
echo 'success';
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @notes:授权回调
|
||
|
* @throws DataNotFoundException
|
||
|
* @throws DbException
|
||
|
* @throws ModelNotFoundException
|
||
|
* @author: wanghousheng
|
||
|
*/
|
||
|
public function redirect()
|
||
|
{
|
||
|
$authorization_code = $this->request->get('auth_code');
|
||
|
if ($authorization_code) {
|
||
|
$obj = new \app\common\library\wxserver\Wholesaler();
|
||
|
$obj->authorizationInfo($authorization_code, $this->request->domain(true));
|
||
|
}
|
||
|
echo 'success';
|
||
|
}
|
||
|
|
||
|
public function callback($appid)
|
||
|
{
|
||
|
$obj = new \app\common\library\wxserver\Wholesaler();
|
||
|
$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)) {
|
||
|
$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;
|
||
|
$obj->release($appid);//审核通过发布版本
|
||
|
} 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 WxwholesalerAccount();
|
||
|
$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']);
|
||
|
}
|
||
|
echo $this->responseText($data);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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'];
|
||
|
$content = !empty($data['Content']) ? $data['Content'] : 'success';
|
||
|
$time = time();
|
||
|
$msgType = 'text';
|
||
|
return sprintf($template, $toUser, $fromUser, $time, $msgType, $content);
|
||
|
}
|
||
|
}
|