国内流行的内容管理系统(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.

168 lines
5.9KB

  1. <?php
  2. /**
  3. * @version $id:api.php 8:38 2010年7月9日 tianya $
  4. * @package DedeBIZ.User
  5. * @copyright Copyright (c) 2022 DedeBIZ.COM
  6. * @license https://www.dedebiz.com/license
  7. * @link https://www.dedebiz.com
  8. */
  9. define('AJAXLOGIN', TRUE);
  10. define('IS_DEDEAPI', TRUE);
  11. require_once(dirname(__FILE__)."/config.php");
  12. AjaxHead();
  13. $action = isset($action)? $action : '';
  14. if ($action === 'is_need_check_code') {
  15. $isNeed = $cfg_ml->isNeedCheckCode($userid);
  16. echo json_encode(array(
  17. "code" => 0,
  18. "msg" => "",
  19. "data" => array(
  20. "isNeed" => $isNeed,
  21. ),
  22. ));
  23. exit;
  24. } else if ($action === 'get_old_email') {
  25. $oldpwd = isset($oldpwd)? $oldpwd : '';
  26. if (empty($oldpwd)) {
  27. echo json_encode(array(
  28. "code" => -1,
  29. "msg" => "旧密码不能为空",
  30. "data" => null,
  31. ));
  32. exit;
  33. }
  34. $row = $dsql->GetOne("SELECT * FROM `#@__member` WHERE mid='".$cfg_ml->M_ID."'");
  35. if (function_exists('password_hash') && !empty($row['pwd_new'])) {
  36. if (!is_array($row) || !password_verify($oldpwd, $row['pwd_new'])) {
  37. echo json_encode(array(
  38. "code" => -1,
  39. "msg" => "旧密码校验错误",
  40. "data" => null,
  41. ));
  42. exit;
  43. }
  44. } else {
  45. if (!is_array($row) || $row['pwd'] != md5($oldpwd)) {
  46. echo json_encode(array(
  47. "code" => -1,
  48. "msg" => "旧密码校验错误",
  49. "data" => null,
  50. ));
  51. exit;
  52. }
  53. }
  54. echo json_encode(array(
  55. "code" => 0,
  56. "msg" => "",
  57. "data" => array(
  58. "email" => $row['email'],
  59. ),
  60. ));
  61. } else if ($action === 'upload') {
  62. if (!$cfg_ml->IsLogin()) {
  63. echo json_encode(array(
  64. "code" => -1,
  65. "msg" => "未登录",
  66. "data" => null,
  67. ));
  68. exit;
  69. }
  70. $target_dir = "uploads/";//上传目录
  71. $type = isset($type)? $type : '';
  72. $allowedTypes = array('image/png', 'image/jpg', 'image/jpeg');
  73. $uploadedFile = $_FILES['file']['tmp_name'];
  74. $fileType = mime_content_type($uploadedFile);
  75. $imgSize = getimagesize($uploadedFile);
  76. if (!in_array($fileType, $allowedTypes) || !$imgSize) {
  77. echo json_encode(array(
  78. "code" => -1,
  79. "msg" => "仅支持图片格式文件",
  80. "data" => null,
  81. ));
  82. exit;
  83. }
  84. if (!is_dir($cfg_basedir.$cfg_user_dir."/{$cfg_ml->M_ID}")) {
  85. MkdirAll($cfg_basedir.$cfg_user_dir."/{$cfg_ml->M_ID}", $cfg_dir_purview);
  86. CloseFtp();
  87. }
  88. if ($type === "face") {
  89. $target_file = $cfg_basedir.$cfg_user_dir."/{$cfg_ml->M_ID}/newface.png";//上传文件名
  90. $target_url = $cfg_mediasurl.'/userup'."/{$cfg_ml->M_ID}/newface.png";
  91. } else {
  92. $nowtme = time();
  93. $rnd = $nowtme.'-'.mt_rand(1000,9999);
  94. $target_file = $cfg_basedir.$cfg_user_dir."/{$cfg_ml->M_ID}/".$rnd.'.png';
  95. $fsize = filesize($_FILES["file"]["tmp_name"]);
  96. $target_url = $cfg_mediasurl.'/userup'."/{$cfg_ml->M_ID}/".$rnd.".png";
  97. $row = $dsql->GetOne("SELECT aid,title,url FROM `#@__uploads` WHERE url LIKE '$target_url' AND mid='".$cfg_ml->M_ID."';");
  98. $uptime = time();
  99. if (is_array($row)) {
  100. $query = "UPDATE `#@__uploads` SET mediatype=1, width='{$imgSize[0]}',height='{$imgSize[1]}',filesize='{$fsize}',uptime='$uptime' WHERE aid='{$row['aid']}'; ";
  101. $dsql->ExecuteNoneQuery($query);
  102. } else {
  103. $inquery = "INSERT INTO `#@__uploads`(url,mediatype,width,height,playtime,filesize,uptime,mid)
  104. VALUES ('$target_url','1','".$imgSize[0]."','".$imgSize[1]."','0','".$fsize."','$uptime','".$cfg_ml->M_ID."'); ";
  105. $dsql->ExecuteNoneQuery($inquery);
  106. }
  107. }
  108. if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
  109. require_once DEDEINC."/libraries/imageresize.class.php";
  110. try{
  111. $image = new ImageResize($target_file);
  112. if ($type === "face") {
  113. $image->crop(150, 150);
  114. } else {
  115. $image->resize($cfg_ddimg_width, $cfg_ddimg_height);
  116. }
  117. $image->save($target_file);
  118. echo json_encode(array(
  119. "code" => 0,
  120. "msg" => "上传成功",
  121. "data" => $target_url,
  122. ));
  123. } catch (ImageResizeException $e) {
  124. echo json_encode(array(
  125. "code" => -1,
  126. "msg" => "图片自动裁剪失败",
  127. "data" => null,
  128. ));
  129. }
  130. } else {
  131. echo json_encode(array(
  132. "code" => -1,
  133. "msg" => "上传失败",
  134. "data" => null,
  135. ));
  136. }
  137. } else {
  138. $format = isset($format) ? "json" : "";
  139. if (!$cfg_ml->IsLogin()) {
  140. if ($format === 'json') {
  141. echo json_encode(array(
  142. "code" => -1,
  143. "msg" => "未登录",
  144. "data" => null,
  145. ));
  146. } else {
  147. echo "";
  148. }
  149. exit;
  150. }
  151. $uid = $cfg_ml->M_LoginID;
  152. !$cfg_ml->fields['face'] && $face = ($cfg_ml->fields['sex'] == '女') ? 'dfgirl' : 'dfboy';
  153. $facepic = empty($face) ? $cfg_ml->fields['face'] : $GLOBALS['cfg_memberurl'].'/templets/images/'.$face.'.png';
  154. if ($format === 'json') {
  155. echo json_encode(array(
  156. "code" => 200,
  157. "msg" => "",
  158. "data" => array(
  159. "username" => $cfg_ml->M_UserName,
  160. "myurl" => $myurl,
  161. "facepic" => $facepic,
  162. "memberurl" => $cfg_memberurl,
  163. ),
  164. ));
  165. exit;
  166. }
  167. }
  168. ?>