Demo.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\library\RsaUtil;
  5. use app\common\library\Wechat;
  6. use think\Db;
  7. /**
  8. * 示例接口
  9. */
  10. class Demo extends Api
  11. {
  12. //如果$noNeedLogin为空表示所有接口都需要登录才能请求
  13. //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
  14. //如果接口已经设置无需登录,那也就无需鉴权了
  15. //
  16. // 无需登录的接口,*表示全部
  17. protected $noNeedLogin = ['*'];
  18. // 无需鉴权的接口,*表示全部
  19. protected $noNeedRight = ['*'];
  20. /**
  21. * 测试方法
  22. *
  23. * @ApiTitle (测试名称)
  24. * @ApiSummary (测试描述信息)
  25. * @ApiMethod (POST)
  26. * @ApiRoute (/api/demo/test/id/{id}/name/{name})
  27. * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  28. * @ApiParams (name="id", type="integer", required=true, description="会员ID")
  29. * @ApiParams (name="name", type="string", required=true, description="用户名")
  30. * @ApiParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据")
  31. * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  32. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  33. * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
  34. * @ApiReturn ({
  35. 'code':'1',
  36. 'msg':'返回成功'
  37. })
  38. */
  39. public function test()
  40. {
  41. $a = '我要反馈一';
  42. $b = mb_substr($a,0,12) . ((mb_strlen($a) > 12) ? '...' : '');
  43. echo $b;
  44. }
  45. /**
  46. * 无需登录的接口
  47. *
  48. */
  49. public function test1()
  50. {
  51. /*$rs0 = Db::query('SHOW TABLE STATUS');
  52. dump($rs0);*/
  53. $rs1 = Db::connect('database_jsc')->query('SHOW TABLE STATUS');
  54. dump($rs1);
  55. $rs2 = Db::connect('database_jsc')->query('SELECT DATABASE()');
  56. dump($rs2);
  57. // $this->success('返回成功', ['action' => 'test1']);
  58. }
  59. /**
  60. * 需要登录的接口
  61. *
  62. */
  63. public function test2()
  64. {
  65. $data = [
  66. 'key1' => 'value1',
  67. 'key2' => 'value2',
  68. 'key3' => 'value3',
  69. 'key4' => 'value4',
  70. 'key5' => 'value5',
  71. ];
  72. $this->success('返回成功', $data);
  73. }
  74. public function send_minimsg(){
  75. $config = config('wxMiniProgram');
  76. $wechat = new Wechat($config['appid'],$config['secret']);
  77. //活动开始
  78. $template_id = $config['mini_msgid_order'];
  79. $data = [
  80. 'thing4' => ['value' => '活动名称'],
  81. 'thing6' => ['value' => '活动地址'],
  82. 'date5' => ['value' => '2025-06-27 14:00'],
  83. 'thing7' => ['value' => '明天开始,不要迟到哦'],
  84. ];
  85. $rs = $wechat->send($template_id,'odWcF7sjejGL7d-0DuCmbmbcH1yA',$data);
  86. dump($rs);
  87. //意见反馈
  88. $template_id = $config['mini_msgid_feedback'];
  89. $data = [
  90. 'thing4' => ['value' => '动画视频功能'],
  91. 'thing5' => ['value' => '无法上传'],
  92. 'thing6' => ['value' => '已经处理完毕了'],
  93. ];
  94. $rs = $wechat->send($template_id,'odWcF7sjejGL7d-0DuCmbmbcH1yA',$data);
  95. dump($rs);
  96. }
  97. /**
  98. * 需要登录且需要验证有相应组的权限
  99. *
  100. */
  101. public function test3()
  102. {
  103. $this->send_score(1, 1);
  104. }
  105. public function send_score($score, $grade_id)
  106. {
  107. $url = 'http://apip-gateway-nrouter-saas-gn-C.month.sdc.cs.icbc:8081/api/mybank/farm/farmplatf/updateVillagerIntegral/V1';
  108. $biz_content = [
  109. 'fSeqNo' => createUniqueNo('fseq', $grade_id),
  110. 'corpCode' => 'xingfulishequ',
  111. 'mobilePhone' => $this->auth->mobile,
  112. 'integralValue' => $score,
  113. 'integralType' => '',
  114. /* 'remark1' => '',
  115. 'remark2' => '',
  116. 'remark3' => '',
  117. 'remark4' => '',
  118. 'remark5' => '',
  119. 'remark6' => '',
  120. 'remark7' => '',*/
  121. ];
  122. $public_key = APP_PATH.'/common/certs/icbc/public_key.pem';
  123. $private_key = APP_PATH.'/common/certs/icbc/private_key.pem';
  124. $rsautil = new RsaUtil($public_key,$private_key);
  125. $sign = $rsautil->publicEncrypt(json_encode($biz_content));
  126. dump($sign);
  127. $data = [
  128. 'app_id' => '10000000000004096993',
  129. 'msg_id' => createUniqueNo('msg', $grade_id),
  130. 'format' => 'json',
  131. 'charset' => 'UTF-8',
  132. // 'encrypt_type'=> 'AES',
  133. 'sign_type' => 'RSA',
  134. 'sign' => $sign,
  135. 'timestamp' => date('Y-m-d H:i:s'),
  136. // 'ca' => '',
  137. 'biz_content' => $biz_content,
  138. ];
  139. $rs = curl_post($url, json_encode($data, JSON_UNESCAPED_UNICODE));
  140. dump($rs);
  141. }
  142. }