国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

186 lines
6.1KB

  1. <?php if(!defined('DEDEINC')) exit('dedecms');
  2. define('MDA_APIHOST', 'http://ssp.desdev.cn');
  3. define('MDA_JQUERY', MDA_APIHOST.'/assets/js/jquery.min.js');
  4. define('MDA_REG_URL', MDA_APIHOST.'/home/register');
  5. define('MDA_FORGOT_PASSWORD_URL', MDA_APIHOST.'/home/forgot_password');
  6. define('MDA_UPDATE_URL', MDA_APIHOST.'/home/update');
  7. define('MDA_API_BIND_USER', MDA_APIHOST.'/api_v1/dedecms/bind_user');
  8. define('MDA_API_LOGIN', MDA_APIHOST.'/api_v1/dedecms/login');
  9. define('MDA_API_CHECK_LOGIN', MDA_APIHOST.'/api_v1/dedecms/check_login');
  10. define('MDA_API_GET_PLACE', MDA_APIHOST.'/api_v1/dedecms/get_place');
  11. define('MDA_VER', '0.0.1');
  12. function mda_http_send($url, $limit=0, $post='', $cookie='', $timeout=15)
  13. {
  14. $return = '';
  15. $matches = parse_url($url);
  16. $scheme = $matches['scheme'];
  17. $host = $matches['host'];
  18. $path = $matches['path'] ? $matches['path'].(@$matches['query'] ? '?'.$matches['query'] : '') : '/';
  19. $port = !empty($matches['port']) ? $matches['port'] : 80;
  20. if (function_exists('curl_init') && function_exists('curl_exec')) {
  21. $ch = curl_init();
  22. curl_setopt($ch, CURLOPT_URL, $scheme.'://'.$host.':'.$port.$path);
  23. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  24. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  25. if ($post) {
  26. curl_setopt($ch, CURLOPT_POST, 1);
  27. $content = is_array($post) ? http_build_query($post) : $post;
  28. curl_setopt($ch, CURLOPT_POSTFIELDS, urldecode($content));
  29. }
  30. if ($cookie) {
  31. curl_setopt($ch, CURLOPT_COOKIE, $cookie);
  32. }
  33. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  34. curl_setopt($ch, CURLOPT_TIMEOUT, 900);
  35. $data = curl_exec($ch);
  36. $status = curl_getinfo($ch);
  37. $errno = curl_errno($ch);
  38. curl_close($ch);
  39. if ($errno ) {
  40. return;
  41. } else {
  42. return !$limit ? $data : substr($data, 0, $limit);
  43. }
  44. }
  45. if ($post) {
  46. $content = is_array($post) ? urldecode(http_build_query($post)) : $post;
  47. $out = "POST $path HTTP/1.0\r\n";
  48. $header = "Accept: */*\r\n";
  49. $header .= "Accept-Language: zh-cn\r\n";
  50. $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
  51. $header .= "User-Agent: ".@$_SERVER['HTTP_USER_AGENT']."\r\n";
  52. $header .= "Host: $host:$port\r\n";
  53. $header .= 'Content-Length: '.strlen($content)."\r\n";
  54. $header .= "Connection: Close\r\n";
  55. $header .= "Cache-Control: no-cache\r\n";
  56. $header .= "Cookie: $cookie\r\n\r\n";
  57. $out .= $header.$content;
  58. } else {
  59. $out = "GET $path HTTP/1.0\r\n";
  60. $header = "Accept: */*\r\n";
  61. $header .= "Accept-Language: zh-cn\r\n";
  62. $header .= "User-Agent: ".@$_SERVER['HTTP_USER_AGENT']."\r\n";
  63. $header .= "Host: $host:$port\r\n";
  64. $header .= "Connection: Close\r\n";
  65. $header .= "Cookie: $cookie\r\n\r\n";
  66. $out .= $header;
  67. }
  68. $fpflag = 0;
  69. $fp = false;
  70. if (function_exists('fsocketopen')) {
  71. $fp = fsocketopen($host, $port, $errno, $errstr, $timeout);
  72. }
  73. if (!$fp) {
  74. $context = stream_context_create(array(
  75. 'http' => array(
  76. 'method' => $post ? 'POST' : 'GET',
  77. 'header' => $header,
  78. 'content' => $content,
  79. 'timeout' => $timeout,
  80. ),
  81. ));
  82. $fp = @fopen($scheme.'://'.$host.':'.$port.$path, 'b', false, $context);
  83. $fpflag = 1;
  84. }
  85. if (!$fp) {
  86. return '';
  87. } else {
  88. stream_set_blocking($fp, true);
  89. stream_set_timeout($fp, $timeout);
  90. @fwrite($fp, $out);
  91. $status = stream_get_meta_data($fp);
  92. if (!$status['timed_out']) {
  93. while (!feof($fp) && !$fpflag) {
  94. if (($header = @fgets($fp)) && ($header == "\r\n" || $header == "\n")) {
  95. break;
  96. }
  97. }
  98. if ($limit) {
  99. $return = stream_get_contents($fp, $limit);
  100. } else {
  101. $return = stream_get_contents($fp);
  102. }
  103. }
  104. @fclose($fp);
  105. return $return;
  106. }
  107. }
  108. function mda_get_setting($skey, $time=false, $real=false)
  109. {
  110. global $dsql;
  111. static $setting = array();
  112. $skey=addslashes($skey);
  113. if (empty($setting[$skey]) || $real) {
  114. $row = $dsql->GetOne("SELECT * FROM `#@__plus_mda_setting` WHERE skey='{$skey}'");
  115. $setting[$skey]['svalue']=$row['svalue'];
  116. $setting[$skey]['stime']=$row['stime'];
  117. }
  118. if (!isset($setting[$skey])) return $time ? array() : null;
  119. if ( $skey == 'channel_uuid' AND empty($setting[$skey]['svalue']) ) return '58b78319a0efe';
  120. if ( $skey == 'channel_secret' AND empty($setting[$skey]['svalue']) ) return 'lDQ97LIb4NXwCV2z';
  121. return $time ? $setting[$skey] : $setting[$skey]['svalue'];
  122. }
  123. function mda_set_setting($skey, $svalue)
  124. {
  125. global $dsql;
  126. $stime=time();
  127. $skey=addslashes($skey);
  128. $svalue=addslashes($svalue);
  129. $sql="UPDATE `#@__plus_mda_setting` SET svalue='{$svalue}',stime='{$stime}' WHERE skey='{$skey}' ";
  130. $dsql->ExecuteNoneQuery($sql);
  131. }
  132. function mda_check_islogin()
  133. {
  134. global $dopost;
  135. $jquery_url = MDA_JQUERY;
  136. $mda_login=MDA_API_CHECK_LOGIN;
  137. echo <<<EOT
  138. <script type="text/javascript" src="{$jquery_url}"></script>
  139. <script type="text/javascript">
  140. (function($){
  141. $.ajax({
  142. type: "GET",
  143. url: "{$mda_login}",
  144. dataType : 'jsonp',
  145. jsonpCallback:"callfunc",
  146. success: function(msg){
  147. if(msg.code != 0){
  148. window.location.href='?dopost=login&nomsg=yes&forward={$dopost}';
  149. //console.log( msg );
  150. }
  151. }
  152. });
  153. })(jQuery)
  154. </script>
  155. EOT;
  156. //exit;
  157. }
  158. function mda_islogin()
  159. {
  160. if(empty($_SESSION['mda_email'])) {
  161. return FALSE;
  162. }
  163. $email = mda_get_setting('email');
  164. $channel_uuid = mda_get_setting('channel_uuid');
  165. $channel_secret = mda_get_setting('channel_secret');
  166. if(empty($email) OR empty($channel_uuid) OR empty($channel_uuid)) {
  167. return FALSE;
  168. }
  169. return TRUE;
  170. }
  171. ?>