Publics.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace app\api\controller;
  3. use think\cache\driver\Redis;
  4. use think\Db;
  5. use think\facade\Validate;
  6. use think\Request;
  7. use OSS\OssClient;
  8. use OSS\Core\OssException;
  9. use Zxing\Qrcode\Decoder\DataBlock;
  10. /**
  11. * @title 公共类
  12. * @controller Publics
  13. */
  14. class Publics extends Base
  15. {
  16. /**
  17. * @title 上传图片
  18. * @desc 上传图片
  19. * @url /api/Publics/uploadLocality
  20. * @method POST
  21. * @tag 基础
  22. *
  23. * @param name:file type:file require:1 desc:上传
  24. * @return name:data@url type:string desc:图片地址
  25. **/
  26. public function uploadLocality(){
  27. $file = request()->file('file');
  28. $dir = dirname(realpath(dirname($_SERVER['SCRIPT_FILENAME']))) . '/public/upload';
  29. if(!file_exists($dir)){
  30. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  31. mkdir($dir, 0700,true);
  32. }
  33. $info = $file->move($dir);
  34. $newName = $info->getSaveName();
  35. $data['url'] = 'http://'.$_SERVER['SERVER_NAME']."/upload/{$newName}";
  36. $this->success('上传成功',$data);
  37. }
  38. /**
  39. * @title 获取系统配置
  40. * @desc 获取系统配置
  41. * @url /api/Publics/config_info
  42. * @method POST
  43. * @tag 基础
  44. *
  45. * @return name:agreement type:string desc:使用条款
  46. * @return name:privacy type:string desc:隐私协议
  47. * @return name:platform_agreement type:string desc:违规处罚
  48. * @return name:about_us type:string desc:关于我们
  49. * @return name:registration_agreement type:string desc:用户注册协议
  50. * @return name:terms_service type:string desc:联通统一认证服务条款
  51. * @return name:chain_on_query type:string desc:链上查询
  52. * @return name:examples_illustrate type:string desc:转赠说明
  53. * @return name:android_version type:string desc:安卓当前版本号
  54. * @return name:android_package type:string desc:安卓包地址
  55. * @return name:ios_package type:string desc:ios地址
  56. **/
  57. public function config_info(){
  58. $nameArray = [
  59. 'agreement',
  60. 'privacy',
  61. 'platform_agreement',
  62. 'about_us',
  63. 'registration_agreement',
  64. 'terms_service',
  65. 'chain_on_query',
  66. 'examples_illustrate',
  67. 'android_version',
  68. 'android_package',
  69. 'ios_package',
  70. 'free_lucky_number',
  71. 'lucky_recharge_price',
  72. 'service_fee',
  73. 'royalties'
  74. ];
  75. $array = getConfig($nameArray);
  76. $this->success('成功',$array);
  77. }
  78. /**
  79. * @title 获取分享的签名
  80. * @desc 获取分享的签名
  81. * @url /api/Publics/getWechatSign
  82. * @method POST
  83. * @tag 基础
  84. *
  85. **/
  86. public function getWechatSign(){
  87. $urls = input('url');
  88. $appid = 'wx9e1cd35013f8ea90';
  89. $secret = 'd5da3e53605c0f0dfbee13bfc57734c2';
  90. $redis = new Redis();
  91. $access_token = $redis->get('access_token');
  92. if (!$access_token){
  93. $access_token = '';
  94. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$secret";
  95. $res=curlRequest($url);
  96. $res = json_decode($res,true);
  97. if (isset($res['access_token'])){
  98. $redis->set('access_token',$res['access_token'],'7000');
  99. $access_token = $res['access_token'];
  100. }
  101. }
  102. $url2 ="https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$access_token."&type=jsapi";
  103. $res2=curlRequest($url2);
  104. $res2 = json_decode($res2,true);
  105. if (!isset($res2) || $res2['errcode']!=0){
  106. $this->error('获取ticket失败');
  107. }
  108. $timestamp = time();
  109. $noncestr = get32Str(15);
  110. // $urls = 'http://jybl.hdlkeji.com/web/h5/';
  111. $string = "jsapi_ticket=".$res2['ticket']."&noncestr=$noncestr&timestamp=$timestamp&url=".$urls;
  112. $sign = sha1($string);
  113. $return = [
  114. 'appid'=>$appid,
  115. 'noncestr'=>$noncestr,
  116. 'timestamp'=>$timestamp,
  117. 'url'=>$urls,
  118. 'sign'=>$sign,
  119. 'ticket'=>$res2['ticket']
  120. ];
  121. $this->success('成功',$return);
  122. }
  123. }