wechat_setting.inc.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: wechat_setting.inc.php 34891 2014-08-20 07:24:39Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
  9. exit('Access Denied');
  10. }
  11. $setting = C::t('common_setting')->fetch_all(array('mobilewechat'));
  12. $setting = (array)unserialize($setting['mobilewechat']);
  13. $apiurl = $_G['siteurl'].'api/mobile/?module=wechat';
  14. require_once DISCUZ_ROOT.'./source/plugin/wechat/wechat.lib.class.php';
  15. require_once DISCUZ_ROOT.'./source/plugin/wechat/wsq.class.php';
  16. require_once DISCUZ_ROOT.'./source/plugin/wechat/setting.class.php';
  17. WeChatSetting::menu();
  18. if(isset($_GET['viewapi'])) {
  19. dheader('location: '.ADMINSCRIPT.'?action=plugins&operation=config&do='.$pluginid.'&identifier=wechat&pmod=api_setting');
  20. }
  21. if(!submitcheck('settingsubmit')) {
  22. if(!$setting['wechat_token']) {
  23. $setting['wechat_token'] = random(16);
  24. $settings = array('mobilewechat' => serialize($setting));
  25. C::t('common_setting')->update_batch($settings);
  26. updatecache('setting');
  27. }
  28. $groupselect = array();
  29. foreach(C::t('common_usergroup')->range_orderby_credit() as $group) {
  30. if($group['type'] != 'member' || $_G['setting']['newusergroupid'] == $group['groupid']) {
  31. $groupselect[$group['type']] .= '<option value="'.$group['groupid'].'"'.($setting['wechat_newusergroupid'] == $group['groupid'] ? ' selected' : '').'>'.$group['grouptitle'].'</option>';
  32. }
  33. }
  34. $usergroups = '<select name="setting[wechat_newusergroupid]"><option value="">'.cplang('plugins_empty').'</option>'.
  35. '<optgroup label="'.$lang['usergroups_member'].'">'.$groupselect['member'].'</optgroup>'.
  36. ($groupselect['special'] ? '<optgroup label="'.$lang['usergroups_special'].'">'.$groupselect['special'].'</optgroup>' : '').
  37. ($groupselect['specialadmin'] ? '<optgroup label="'.$lang['usergroups_specialadmin'].'">'.$groupselect['specialadmin'].'</optgroup>' : '').
  38. '<optgroup label="'.$lang['usergroups_system'].'">'.$groupselect['system'].'</optgroup></select>';
  39. showtips(lang('plugin/wechat', 'wechat_tips', array('url' => $apiurl)));
  40. showformheader('plugins&operation=config&do='.$pluginid.'&identifier=wechat&pmod=wechat_setting', 'enctype');
  41. showtableheader();
  42. showsetting(lang('plugin/wechat', 'wechat_mptype'), array('setting[wechat_mtype]', array(
  43. array(0, lang('plugin/wechat', 'wechat_mptype_0'), array('qrcode' => 'none')),
  44. array(2, lang('plugin/wechat', 'wechat_mptype_2'), array('qrcode' => 'none')),
  45. )), $setting['wechat_mtype'], 'mradio', 0, 0, lang('plugin/wechat', 'wechat_mptype_comment'));
  46. showtagheader('tbody', 'qrcode', $setting['wechat_mtype'] == 1);
  47. showsetting(lang('plugin/wechat', 'wechat_qrcode'), 'wechat_qrcode', '', 'file', 0, 0, lang('plugin/wechat', 'wechat_qrcode_comment', array('qrcode' => $qrcode)));
  48. showtagfooter('tbody');
  49. showtablefooter();
  50. showtableheader(lang('plugin/wechat', 'wechat_func_setting'));
  51. showsetting(lang('plugin/wechat', 'wechat_allowregister'), 'setting[wechat_allowregister]', $setting['wechat_allowregister'], 'radio', 0, 1, lang('plugin/wechat', 'wechat_allowregister_comment'));
  52. showsetting(lang('plugin/wechat', 'wechat_allowfastregister'), 'setting[wechat_allowfastregister]', $setting['wechat_allowfastregister'], 'radio', 0, 0, lang('plugin/wechat', 'wechat_allowfastregister_comment'));
  53. showsetting(lang('plugin/wechat', 'wechat_disableregrule'), 'setting[wechat_disableregrule]', $setting['wechat_disableregrule'], 'radio', 0, 0, lang('plugin/wechat', 'wechat_disableregrule_comment'));
  54. showsetting(lang('plugin/wechat', 'wechat_confirmtype'), 'setting[wechat_confirmtype]', $setting['wechat_confirmtype'], 'radio', 0, 0, lang('plugin/wechat', 'wechat_confirmtype_comment'));
  55. showsetting(lang('plugin/wechat', 'wechat_newusergroupid'), '', '', $usergroups, 0, 0, lang('plugin/wechat', 'wechat_newusergroupid_comment'));
  56. showtagfooter('tbody');
  57. showsetting(lang('plugin/wechat', 'wechat_followurl'), 'setting[wechat_followurl]', $setting['wechat_followurl'], 'text', 0, 0, lang('plugin/wechat', 'wechat_followurl_comment'));
  58. showtagfooter('tbody');
  59. showtableheader(lang('plugin/wechat', 'wechat_service_setting'));
  60. showsetting(lang('plugin/wechat', 'wechat_url'), '', '', '<span style="white-space:nowrap">'.$apiurl.'</span>');
  61. showsetting(lang('plugin/wechat', 'wechat_token'), 'setting[wechat_token]', $setting['wechat_token'], 'text');
  62. showtablefooter();
  63. showtableheader(lang('plugin/wechat', 'wechat_devid_setting'));
  64. showsetting(lang('plugin/wechat', 'wechat_appId'), 'setting[wechat_appId]', $setting['wechat_appId'], 'text');
  65. showsetting(lang('plugin/wechat', 'wechat_appsecret'), 'setting[wechat_appsecret]', $setting['wechat_appsecret'], 'text');
  66. showtablefooter();
  67. showtableheader();
  68. showsubmit('settingsubmit');
  69. showtablefooter();
  70. showformfooter();
  71. } else {
  72. if($_GET['setting']['wechat_mtype'] == 2 && !$_GET['setting']['wechat_appId']) {
  73. cpmsg(lang('plugin/wechat', 'wechat_at_need'), '', 'error');
  74. }
  75. if($_GET['setting']['wechat_appId'] && $_GET['setting']['wechat_appsecret']) {
  76. require_once DISCUZ_ROOT . './source/plugin/wechat/wechat.lib.class.php';
  77. $wechat_client = new WeChatClient($_GET['setting']['wechat_appId'], $_GET['setting']['wechat_appsecret']);
  78. if(!$wechat_client->getAccessToken(1, 1)) {
  79. cpmsg(lang('plugin/wechat', 'wechat_at_geterror'), '', 'error');
  80. }
  81. $option = array(
  82. 'scene_id' => 100000,
  83. 'expire' => 30,
  84. 'ticketOnly' => 1
  85. );
  86. $ticket = $wechat_client->getQrcodeTicket($option);
  87. if(!$wechat_client->getQrcodeImgUrlByTicket($ticket)) {
  88. cpmsg(lang('plugin/wechat', 'wechat_at_qrgeterror'), '', 'error');
  89. }
  90. }
  91. $_GET['setting']['wechat_qrtype'] = !$_GET['setting']['wechat_mtype'] ? 3 : 0;
  92. $_GET['setting']['wechat_token'] = $_GET['setting']['wechat_token'] ? $_GET['setting']['wechat_token'] : random(16);
  93. if($_FILES['wechat_qrcode']['tmp_name']) {
  94. $upload = new discuz_upload();
  95. if(!$upload->init($_FILES['wechat_qrcode'], 'common', random(3, 1), random(8)) || !$upload->save()) {
  96. cpmsg($upload->errormessage(), '', 'error');
  97. }
  98. $_GET['setting']['wechat_qrcode'] = $upload->attach['attachment'];
  99. }
  100. if($_GET['setting']['wechat_followurl']) {
  101. $_GET['setting']['wechat_followurl'] = (!preg_match('/^http:\/\//', $_GET['setting']['wechat_followurl']) ? 'http://' : '').$_GET['setting']['wechat_followurl'];
  102. $parse = parse_url($_GET['setting']['wechat_followurl']);
  103. if(!$parse['host'] || $parse['host'] != 'mp.weixin.qq.com') {
  104. cpmsg(lang('plugin/wechat', 'wsq_followurl_error'), '', 'error');
  105. }
  106. }
  107. if($setting['wsq_siteid']) {
  108. $siteinfo = wsq::edit($setting['wsq_sitename'],
  109. $setting['wsq_siteurl'],
  110. $setting['wsq_sitelogo'],
  111. $setting['wsq_sitesummary'],
  112. $_GET['setting']['wechat_mtype'],
  113. $_GET['setting']['wechat_qrtype'],
  114. $setting['wsq_siteip'],
  115. $_GET['setting']['wechat_followurl'],
  116. $_GET['setting']['wechat_appId'],
  117. $_GET['setting']['wechat_appsecret'],
  118. $_GET['setting'] + $setting
  119. );
  120. if(!$siteinfo || $siteinfo->code) {
  121. cpmsg(lang('plugin/wechat', 'wsq_api_edit_error'), '', 'error');
  122. }
  123. }
  124. $settings = array('mobilewechat' => serialize($_GET['setting'] + $setting));
  125. C::t('common_setting')->update_batch($settings);
  126. updatecache('setting');
  127. cpmsg('setting_update_succeed', 'action=plugins&operation=config&do='.$pluginid.'&identifier=wechat&pmod=wechat_setting', 'succeed');
  128. }
  129. function formathook($hook) {
  130. return '<b>File:</b> '.$hook['plugin'].'/'.$hook['include'].' <b>Method:</b> '.$hook['class'].'->'.$hook['method'];
  131. }
  132. ?>