Demo.php 4.7 KB

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