| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Service\qyWechatService;
- use Illuminate\Http\Request;
- use Illuminate\Support\Str;
- class TestController extends BaseController
- {
- public function getSignatures(Request $request)
- {
- $data = $request->all();
- $url = $data['url'];
- if(empty($url)) return $this->json_return(201, 'URL不能为空');
- $nonceStr = Str::random();
- $timestamp = time();
- // 1. 企业级签名 (wx.config)
- $wechat = new qyWechatService();
- list($status, $ticket) = $wechat->getJsApiTicket();
- if(! $status) {
- return $this->json_return(201, $ticket);
- }
- $configSignature = $wechat->makeSignature($ticket, $nonceStr, $timestamp, $url);
- // 2. 应用级签名 (wx.agentConfig)
- list($status, $agentTicket) = $wechat->getAgentTicket();
- if(! $status) {
- return $this->json_return(201, $agentTicket);
- }
- $agentSignature = $wechat->makeSignature($agentTicket, $nonceStr, $timestamp, $url);
- $return = [
- 'corpid' => $wechat->corpId,
- 'agentid' => $wechat->agentId,
- 'timestamp' => $timestamp,
- 'nonceStr' => $nonceStr,
- 'configSignature' => $configSignature,
- 'agentSignature' => $agentSignature,
- ];
- return $this->json_return(200,'',$return);
- }
- }
|