Publics.php 3.7 KB

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