人人商城

remote.ctrl.php 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. load()->func('communication');
  8. load()->model('attachment');
  9. load()->model('miniapp');
  10. $dos = array('display', 'save', 'test_setting', 'upload_remote');
  11. $do = in_array($do, $dos) ? $do : 'display';
  12. $_W['page']['title'] = '远程附件 - 公众号选项';
  13. permission_check_account_user('profile_setting_remote');
  14. if (!empty($_GPC['version_id'])) {
  15. $version_id = intval($_GPC['version_id']);
  16. $version_info = miniapp_version($version_id);
  17. }
  18. $remote = $_W['setting']['remote_complete_info'][$_W['uniacid']];
  19. if ($do == 'upload_remote') {
  20. if (!empty($_W['setting']['remote_complete_info'][$_W['uniacid']]['type'])) {
  21. $result = file_dir_remote_upload(ATTACHMENT_ROOT . 'images/' . $_W['uniacid']);
  22. if (is_error($result)) {
  23. itoast($result['message'], url('profile/remote'), 'info');
  24. } else {
  25. itoast('上传成功!', url('profile/remote'), 'success');
  26. }
  27. } else {
  28. itoast('请先填写并开启远程附件设置。', '', 'info');
  29. }
  30. }
  31. if ($do == 'display') {
  32. $safe_path = safe_gpc_path(IA_ROOT . '/attachment/images/' . $_W['uniacid']);
  33. if (!empty($safe_path)) {
  34. $local_attachment = file_dir_exist_image($safe_path);
  35. } else {
  36. $local_attachment = array();
  37. }
  38. }
  39. if ($do == 'save'){
  40. $remote_data = array(
  41. 'type' => $_GPC['type'],
  42. 'qiniu' => array(
  43. 'accesskey' => $_GPC['qiniu']['accesskey'],
  44. 'secretkey' => strexists($_GPC['qiniu']['secretkey'], '*') ? $remote['qiniu']['secretkey'] : trim($_GPC['qiniu']['secretkey']),
  45. 'bucket' => $_GPC['qiniu']['bucket'],
  46. 'url' => $_GPC['qiniu']['url'],
  47. )
  48. );
  49. if ($remote_data['type'] == ATTACH_QINIU) {
  50. if (empty($remote_data['qiniu']['accesskey'])) {
  51. itoast ('请填写Accesskey', referer (), 'info');
  52. }
  53. if (empty($remote_data['qiniu']['secretkey'])) {
  54. itoast ('secretkey', referer (), 'info');
  55. }
  56. if (empty($remote_data['qiniu']['bucket'])) {
  57. itoast ('请填写bucket', referer (), 'info');
  58. }
  59. if (empty($remote_data['qiniu']['url'])) {
  60. itoast ('请填写url', referer (), 'info');
  61. } else {
  62. $remote_data['qiniu']['url'] = strexists ($remote_data['qiniu']['url'], 'http') ? trim ($remote_data['qiniu']['url'], '/') : 'http://' . trim ($remote_data['qiniu']['url'], '/');
  63. }
  64. $auth = attachment_qiniu_auth ($remote_data['qiniu']['accesskey'], $remote_data['qiniu']['secretkey'], $remote_data['qiniu']['bucket']);
  65. if (is_error ($auth)) {
  66. $message = $auth['message']['error'] == 'bad token' ? 'Accesskey或Secretkey填写错误, 请检查后重新提交' : 'bucket填写错误或是bucket所对应的存储区域选择错误,请检查后重新提交';
  67. itoast ($message, referer (), 'info');
  68. }
  69. }
  70. $_W['setting']['remote_complete_info'][$_W['uniacid']] = $remote_data;
  71. setting_save($_W['setting']['remote_complete_info'], 'remote');
  72. itoast('保存成功', '', 'success');
  73. }
  74. if ($do == 'test_setting') {
  75. $type = $_GPC['type'];
  76. if ($type == ATTACH_QINIU) {
  77. $_GPC['secretkey'] = strexists($_GPC['secretkey'], '*') ? $remote['qiniu']['secretkey'] : $_GPC['secretkey'];
  78. $auth= attachment_qiniu_auth(trim($_GPC['accesskey']), trim($_GPC['secretkey']), trim($_GPC['bucket']));
  79. if (is_error($auth)) {
  80. iajax(-1, '配置失败,请检查配置。注:请检查存储区域是否选择的是和bucket对应<br/>的区域', '');
  81. }
  82. $url = $_GPC['url'];
  83. $url = strexists($url, 'http') ? trim($url, '/') : 'http://'.trim($url, '/');
  84. $filename = 'MicroEngine.ico';
  85. $response = ihttp_request($url. '/'.$filename, array(), array('CURLOPT_REFERER' => $_SERVER['SERVER_NAME']));
  86. if (is_error($response)) {
  87. iajax(-1, '配置失败,七牛访问url错误');
  88. }
  89. if (intval($response['code']) != 200) {
  90. iajax(-1, '配置失败,七牛访问url错误,请保证bucket为公共读取的');
  91. }
  92. $image = getimagesizefromstring($response['content']);
  93. if (!empty($image) && strexists($image['mime'], 'image')) {
  94. iajax(0,'配置成功');
  95. } else {
  96. iajax(-1, '配置失败,七牛访问url错误');
  97. }
  98. }
  99. }
  100. template('profile/remote');