123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace App\Http\Controllers\Admin;
- use App\Http\Controllers\Controller;
- use App\Log;
- use App\Models\System\Users;
- use App\Service\MsgService;
- use App\Support\qyApi\QyCommon;
- use Illuminate\Http\Request;
- include '../app/Libs/qyWeChatSDK/WXBizMsgCrypt.php';
- class AuthController extends Controller
- {
- private $aesKey;
- private $authToken;
- /*
- * 初始化
- * */
- public function __construct()
- {
- parent::__construct();
- $component = config('qyWechat.suite_info');
- if(empty($component)) {
- return self::returnValue([], 1001);
- }
- $this->aesKey = $component['aes_key'];
- $this->authToken = $component['auth_token'];
- }
- /*
- * 获取验证票据 ComponentVerifyTicket
- * */
- public function getVerifyTicket(Request $request)
- {
- $sVerifyMsgSig = $request->input('msg_signature');
- $sVerifyTimeStamp = $request->input('timestamp');
- $sVerifyNonce = $request->input('nonce');
- if($request->isMethod('get')){ // 初步校验回调链接合法性
- $sVerifyEchoStr = $request->input('echostr');
- $sEchoStr = ""; # 需要返回的明文
- $crypt = new \WXBizMsgCrypt($this->authToken, $this->aesKey, $this->corpid);
- $errCode = $crypt->VerifyURL($sVerifyMsgSig, $sVerifyTimeStamp, $sVerifyNonce, $sVerifyEchoStr, $sEchoStr);
- if ($errCode == 0) {
- echo $sEchoStr;
- } else {
- Log::logInfo('Errcode:'.$errCode, [], 'verifyTicketGetFail');
- }
- } elseif ($request->isMethod('post')){
- $requestMsg = file_get_contents('php://input');
- $sMsg = ""; # 需要返回的明文
- $crypt = new \WXBizMsgCrypt($this->authToken, $this->aesKey, $this->suiteId);
- $errCode = $crypt->DecryptMsg($sVerifyMsgSig, $sVerifyTimeStamp, $sVerifyNonce, $requestMsg, $sMsg);
- // Log::logInfo('解密后内容'. $sMsg, [], '0316');
- echo 'success';
- // if($errCode == 0) {
- $result = MsgService::responseCommand($sMsg);
- // if($result) {
- // echo 'success';
- // }
- // exit;
- // } else {
- // Log::logError('verifyTicket获取失败', ['errCode' => $errCode], 'verifyTicketPostFail');
- // }
- }
- }
- /**
- * 获取微信广告的授权二维码
- * @param Request $request
- */
- public function getWxadAuthCode(Request $request) {
- $url = 'https://developers.e.qq.com/oauth/authorize?';
- $wxadConfig = config('wxad');
- $sysGroupId = $request->input('sys_group_id');
- $userId = $request->input('admin_id');
- // 用户
- $user = Users::query()->find($userId);
- $sysGroupId = Users::query()
- ->where('enable', 1)
- ->where(function ($query) use($user, $userId, $sysGroupId) {
- if($user->is_system_admin) {
- $query->where('group_admin_id', $sysGroupId);
- } else {
- $query->where('id', $userId);
- }
- })
- ->value('group_admin_id');
- $query = http_build_query([
- 'client_id' => $wxadConfig['client_id'],
- 'state' => $sysGroupId,
- // 'state' => 'novel',
- 'scope' => '',
- 'redirect_uri' => $wxadConfig['redirect_uri'],
- 'account_type' => "ACCOUNT_TYPE_WECHAT",
- 'account_display_number' => 2
- ]);
- Log::logInfo('getWxadAuthCode', [
- 'params' => $request->all(),
- 'url' => $url.$query
- ], 'interface');
- echo $url.$query;
- }
- }
|