TestController.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Service\qyWechatService;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Support\Str;
  6. class TestController extends BaseController
  7. {
  8. public function getSignatures(Request $request)
  9. {
  10. $data = $request->all();
  11. $url = $data['url'];
  12. if(empty($url)) return $this->json_return(201, 'URL不能为空');
  13. $nonceStr = Str::random();
  14. $timestamp = time();
  15. // 1. 企业级签名 (wx.config)
  16. $wechat = new qyWechatService();
  17. list($status, $ticket) = $wechat->getJsApiTicket();
  18. if(! $status) {
  19. return $this->json_return(201, $ticket);
  20. }
  21. $configSignature = $wechat->makeSignature($ticket, $nonceStr, $timestamp, $url);
  22. // 2. 应用级签名 (wx.agentConfig)
  23. list($status, $agentTicket) = $wechat->getAgentTicket();
  24. if(! $status) {
  25. return $this->json_return(201, $agentTicket);
  26. }
  27. $agentSignature = $wechat->makeSignature($agentTicket, $nonceStr, $timestamp, $url);
  28. $return = [
  29. 'corpid' => $wechat->corpId,
  30. 'agentid' => $wechat->agentId,
  31. 'timestamp' => $timestamp,
  32. 'nonceStr' => $nonceStr,
  33. 'configSignature' => $configSignature,
  34. 'agentSignature' => $agentSignature,
  35. ];
  36. return $this->json_return(200,'',$return);
  37. }
  38. }