admincp_callback.inc.php 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * DZAPP Haodai Admin Control Panel -- Callback View
  4. *
  5. * @copyright (c) 2013 DZAPP. (http://www.dzapp.cn)
  6. * @author BranchZero <branchzero@gmail.com>
  7. */
  8. if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) exit('Access Denied!');
  9. include_once DISCUZ_ROOT.'./data/dzapp_haodai_config.php';
  10. include_once DISCUZ_ROOT.'./source/plugin/dzapp_haodai/haodai.api.class.php';
  11. @include_once DISCUZ_ROOT.'./data/sysdata/cache_dzapp_haodai_setting.php';
  12. $lang = array_merge($lang, $scriptlang['dzapp_haodai']);
  13. if(!$_GET['want']){
  14. showtableheader($lang['callback_info'].' <a href="admin.php?action=plugins&operation=config&identifier=dzapp_haodai&pmod=admincp_callback&want=import">['.$lang['click_to_import'].']</a>');
  15. showtablerow('', array('class="td24"'), array($lang['appkey'], HD_AKEY));
  16. showtablerow('', array('class="td24"'), array($lang['appsecret'], HD_SKEY));
  17. showtablerow('', array('class="td24"'), array($lang['ref'], HD_REF));
  18. showtablerow('', array('class="td24"'), array($lang['callback_url'], HD_CALLBACK_URL));
  19. showtablerow('', array('class="td24"'), array($lang['host_url'], HD_API_HOST));
  20. if(!isset($hd_token)){
  21. $oauth = new HaoDaiOAuth(HD_AKEY, HD_SKEY);
  22. $auth_url = $oauth->getAuthorizeURL(HD_CALLBACK_URL);
  23. showtablerow('', array('class="td24"'), array($lang['callback_status'], '<font color="red">'.$lang['callback_expired'].'</font> <a href="'.$auth_url.'"><img src="source/plugin/dzapp_haodai/images/haodai_login.png" class="vmiddle"></a>'));
  24. }else{
  25. if(isset($hd_token['expires']) && TIMESTAMP > $hd_token['expires'] - 3600){
  26. $client = new HaoDaiClient(HD_AKEY, HD_SKEY);
  27. $client->set_debug(0);
  28. $result = $client->haodai_check_AccessToken();
  29. if($result['rs_code'] != '1000'){
  30. if($result['rs_code'] == '2100'){
  31. $new_hd_token = $client->oauth->getAccessToken('token', $hd_token);
  32. require_once libfile('function/cache');
  33. writetocache('dzapp_haodai_setting', getcachevars(array('hd_token' => $new_hd_token)));
  34. showtablerow('', array('class="td24"'), array($lang['callback_status'], '<font color="green">'.$lang['valid'].'</font>'));
  35. }else{
  36. $auth_url = $client->oauth->getAuthorizeURL(HD_CALLBACK_URL);
  37. showtablerow('', array('class="td24"'), array($lang['callback_status'], '<font color="red">'.$lang['callback_expired'].'</font> <a href="'.$auth_url.'"><img src="source/plugin/dzapp_haodai/images/haodai_login.png" class="vmiddle"></a>'));
  38. }
  39. }else{
  40. showtablerow('', array('class="td24"'), array($lang['callback_status'], '<font color="green">'.$lang['valid'].'</font>'));
  41. }
  42. }elseif(isset($hd_token['expires']) && TIMESTAMP < $hd_token['expires'] - 3600){
  43. showtablerow('', array('class="td24"'), array($lang['callback_status'], '<font color="green">'.$lang['valid'].'</font>'));
  44. }else{
  45. $oauth = new HaoDaiOAuth(HD_AKEY, HD_SKEY);
  46. $auth_url = $oauth->getAuthorizeURL(HD_CALLBACK_URL);
  47. showtablerow('', array('class="td24"'), array($lang['callback_status'], '<font color="red">'.$lang['callback_expired'].'</font> <a href="'.$auth_url.'"><img src="source/plugin/dzapp_haodai/images/haodai_login.png" class="vmiddle"></a>'));
  48. }
  49. }
  50. showtablefooter();
  51. }elseif($_GET['want'] == 'import'){
  52. if(!submitcheck('ok')){
  53. showformheader('plugins&operation=config&identifier=dzapp_haodai&pmod=admincp_callback&want=import');
  54. showtableheader('import_callback');
  55. showsetting($lang['appkey'], 'AKEY', defined('HD_AKEY') ? HD_AKEY : '', 'text');
  56. showsetting($lang['appsecret'], 'SKEY', defined('HD_SKEY') ? HD_SKEY : '', 'text');
  57. showsetting($lang['ref'], 'REF', defined('HD_REF') ? HD_REF : '', 'text');
  58. showsetting($lang['callback_url'], 'CALLBACK_URL', defined('HD_CALLBACK_URL') ? HD_CALLBACK_URL : $_G['siteurl'].'plugin.php?id=dzapp_haodai:callback', 'text');
  59. showsetting($lang['host_url'], 'API_HOST', defined('HD_API_HOST') ? HD_API_HOST : 'http://api.haodai.com/', 'text');
  60. showsubmit('ok', "ok");
  61. showtablefooter();
  62. showformfooter();
  63. }else{
  64. $config = array();
  65. $config['HD_REF'] = $_GET['REF'];
  66. $config['HD_AKEY'] = $_GET['AKEY'];
  67. $config['HD_SKEY'] = $_GET['SKEY'];
  68. $config['HD_CALLBACK_URL'] = $_GET['CALLBACK_URL'];
  69. $config['HD_API_HOST'] = $_GET['API_HOST'];
  70. $config['HD_CITY'] = defined('HD_CITY') ? HD_CITY : '';
  71. $config = daddslashes($config);
  72. $configfile = "<?php \r\n";
  73. foreach($config as $key => $value){
  74. $configfile .= "define('$key', '$value');\r\n";
  75. }
  76. $configfile .= "?>";
  77. $file = DISCUZ_ROOT."./data/dzapp_haodai_config.php";
  78. $fp = fopen($file, 'w');
  79. fwrite($fp, $configfile);
  80. fclose($fp);
  81. cpmsg('import_succeed', 'action=plugins&operation=config&identifier=dzapp_haodai&pmod=admincp_callback', 'succeed');
  82. }
  83. }
  84. ?>