欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PHP微商城开源代码实例

程序员文章站 2023-12-19 15:46:46
本文实例为大家分享了php微商城的具体代码,供大家参考,具体内容如下

本文实例为大家分享了php微商城的具体代码,供大家参考,具体内容如下

<?php
require '../conn/conn2.php';
require '../conn/function.php';

$d_domain = splitx($_server["http_host"] . $_server["php_self"], "/weixin", 0);
$sql = "select * from sl_config";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
if (mysqli_num_rows($result) > 0) {
  $c_webtitle = $row["c_title"];
  $c_wtoken = $row["c_wtoken"];
  $c_logo = $row["c_logo"];
  $c_ico = $row["c_ico"];
  $c_wx_appidz = $row["c_wx_appid"];
  $c_wx_appsecretz = $row["c_wx_appsecret"];
}
$signature = $_request["signature"];
$nonce = $_request["nonce"];
$timestamp = $_request["timestamp"];
$echostr = $_request["echostr"];
if ($echostr != "") {
  $array = array();
  $array = array($c_wtoken, $timestamp, $nonce);
  sort($array);
  $str = sha1(implode($array));
  if ($str == $signature && $echostr) {
    echo $echostr;
    exit;
  }
}
if ($signature != "" && $echostr == "") {
  $postarr = file_get_contents("php://input");
  $postobj = simplexml_load_string($postarr);
  $tousername = $postobj->fromusername;
  $fromusername = $postobj->tousername;
  $msgtype = $postobj->msgtype;
  $strevent = $postobj->event;
  $eventkey = $postobj->eventkey;

  file_put_contents("test.txt", $postarr);

  if ($msgtype == "event") {
    
    if ($strevent == "subscribe") {
      $strsend = events( $tousername,$fromusername, "key_" . getrs("select * from sl_reply where r_key like '新用户关注'", "r_reply"));

      $sqlx = "select * from sl_member where m_qqid like '" . $tousername . "'";
      $resultx = mysqli_query($conn, $sqlx);
      if (mysqli_num_rows($resultx) > 0) {
        mysqli_query($conn, "update sl_member set m_subscribe=1 where m_qqid like '" . $tousername . "'");
      } else {
        $access_token = json_decode(getbody("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $c_wx_appidz . "&secret=" . $c_wx_appsecretz, ""))->access_token;
        $m_info = json_decode(getbody("https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $access_token . "&openid=" . $tousername . "&lang=zh_cn", ""));

        $m_login = $m_info->nickname;
        $m_pic = $m_info->headimgurl;
        $m_city = $m_info->city;
        $m_province = $m_info->province;
        $m_country = $m_info->country;
        mysqli_query($conn, "insert into sl_member(m_login,m_pwd,m_qqid,m_pic,m_fen,m_regtime,m_add,m_name,m_subscribe) values('" . $m_login . "','" . $tousername . "','" . $tousername . "','" . $m_pic . "',0,'" . date('y-m-d h:i:s') . "','" . $m_country . $m_province . $m_city . "','" . $m_login . "',1)");
        $sql = "select * from sl_member order by m_id desc limit 1";
        $result = mysqli_query($conn, $sql);
        $row = mysqli_fetch_assoc($result);
        if (mysqli_num_rows($result) > 0) {
          $m_id = $row["m_id"];
        }
        uplevel($m_id);
      }
    }
    if ($strevent == "unsubscribe") {
      mysqli_query($conn, "update sl_member set m_subscribe=0 where m_qqid like '" . $tousername . "'");
    }
    if ($strevent == "click") {;
      $strsend = events( $tousername,$fromusername, $eventkey);
      
    }
  }
  if ($msgtype == "text") {
    $e_content = $postobj->content;
    $strsend = text( $tousername, $fromusername,$e_content);

    file_put_contents("test3.txt", $strsend);
  }
  echo $strsend;
}
function events($fromusername, $tousername, $key) {
  global $conn, $d_domain, $c_ico;
  $e_type = getrs("select * from sl_event where e_id=" . splitx($key, "_", 1), "e_type");
  $e_content = getrs("select * from sl_event where e_id=" . splitx($key, "_", 1), "e_content");
  switch ($e_type) {
    case "text":
      $events = "<xml>
						<tousername><![cdata[" . $fromusername . "]]></tousername>
						<fromusername><![cdata[" . $tousername . "]]></fromusername>
						<createtime>" . date('y-m-d h:i:s') . "</createtime>
						<msgtype><![cdata[text]]></msgtype>
						<content><![cdata[" . $e_content . "]]></content>
						<funcflag>0<funcflag>
						</xml>";
    break;
    case "article":
      $events = "<xml>
						<tousername><![cdata[" . $fromusername . "]]></tousername>
						<fromusername><![cdata[" . $tousername . "]]></fromusername>
						<createtime>" . date('y-m-d h:i:s') . "</createtime>
						<msgtype><![cdata[news]]></msgtype>
						<articlecount>1</articlecount>
						<articles>";
      $emptystr = "<item>
							<title><![cdata[文章已删除]]></title> 
							<description><![cdata[文章已删除]]></description>
							<picurl><![cdata[http://" . $d_domain . "/" . $c_ico . "]]></picurl>
							<url><![cdata[http://" . $d_domain . "/wap_index.php]]></url>
						</item>";
      switch (substr($e_content, 0, 1)) {
        case "t":
          if (getrs("select * from sl_text where t_id=" . substr($e_content, -(strlen($e_content) - 1)), "t_title") != "") {
            $events = $events . "<item>
												<title><![cdata[" . lang(getrs("select * from sl_text where t_id=" . substr($e_content, -(strlen($e_content) - 1)), "t_title")) . "]]></title>
												<description><![cdata[" . lang(getrs("select * from sl_text where t_id=" . substr($e_content, -(strlen($e_content) - 1)), "t_description")) . "]]></description>
												<picurl><![cdata[http://" . $d_domain . "/" . getrs("select * from sl_text where t_id=" . substr($e_content, -(strlen($e_content) - 1)), "t_pic") . "]]></picurl>
												<url><![cdata[http://" . $d_domain . "/wap_index.php?type=text&s_id=" . substr($e_content, -(strlen($e_content) - 1)) . "]]></url>
											</item>";
          } else {
            $events = $events . $emptystr;
          }
        break;
        case "n":
          if (getrs("select * from sl_news where n_id=" . substr($e_content, strlen($e_content) - 1), "n_title") != "") {
            $events = $events . "<item>
												<title><![cdata[" . lang(getrs("select * from sl_news where n_id=" . substr($e_content, -(strlen($e_content) - 1)), "n_title")) . "]]></title>
												<description><![cdata[" . lang(getrs("select * from sl_news where n_id=" . substr($e_content, -(strlen($e_content) - 1)), "n_short")) . "]]></description>
												<picurl><![cdata[http://" . $d_domain . "/" . getrs("select * from sl_news where n_id=" . substr($e_content, -(strlen($e_content) - 1)), "n_pic") . "]]></picurl>
												<url><![cdata[http://" . $d_domain . "/wap_index.php?type=newsinfo&s_id=" . substr($e_content, -(strlen($e_content) - 1)) . "]]></url>
												</item>";
          } else {
            $events = $events . $emptystr;
          }
        break;
        case "p":
          if (getrs("select * from sl_product where p_id=" . substr($e_content, strlen($e_content) - 1), "p_title") != "") {
            $events = $events . "<item>
											<title><![cdata[" . lang(getrs("select * from sl_product where p_id=" . substr($e_content, -(strlen($e_content) - 1)), "p_title")) . "]]></title>
											<description><![cdata[" . lang(getrs("select * from sl_product where p_id=" . substr($e_content, -(strlen($e_content) - 1)), "p_short")) . "]]></description>
											<picurl><![cdata[http://" . $d_domain . "/" . splitx(getrs("select * from sl_product where p_id=" . substr($e_content, -(strlen($e_content) - 1)), "p_path"), "|", 0) . "]]></picurl>
											<url><![cdata[http://" . $d_domain . "/wap_index.php?type=productinfo&s_id=" . substr($e_content, -(strlen($e_content) - 1)) . "]]></url>
											</item>";
          } else {
            $events = $events . $emptystr;
          }
        break;
        case "f":
          if (getrs("select * from sl_form where f_id=" . substr($e_content, -(strlen($e_content) - 1)), "f_title") != "") {
            $events = $events . "<item>
											<title><![cdata[" . lang(getrs("select * from sl_form where f_id=" . substr($e_content, -(strlen($e_content) - 1)), "f_title")) . "]]></title>
											<description><![cdata[" . lang(getrs("select * from sl_form where f_id=" . substr($e_content, -(strlen($e_content) - 1)), "f_description")) . "]]></description>
											<picurl><![cdata[http://" . $d_domain . "/" . getrs("select * from sl_form where f_id=" . substr($e_content, -(strlen($e_content) - 1)), "f_pic") . "]]></picurl>
											<url><![cdata[http://" . $d_domain . "/wap_index.php?type=form&s_id=" . substr($e_content, -(strlen($e_content) - 1)) . "]]></url>
											</item>";
          } else {
            $events = $events . $emptystr;
          }
        break;
        case "c":
          $events = $events . "<item>
											<title><![cdata[联系我们]]></title>
											<description><![cdata[联系我们]]></description>
											<picurl><![cdata[http://" . $d_domain . "/" . $c_ico . "]]></picurl>
											<url><![cdata[http://" . $d_domain . "/wap_index.php?type=contact&s_id=1]]></url>
											</item>";
        break;
        case "g":
          $events = $events . "<item>
										<title><![cdata[在线留言]]></title>
										<description><![cdata[在线留言]]></description>
										<picurl><![cdata[http://" . $d_domain . "/" . $c_ico . "]]></picurl>
										<url><![cdata[http://" . $d_domain . "/wap_index.php?type=guestbook&s_id=1]]></url>
										</item>";
      }
      $events = $events . "</articles></xml>";
    break;
    case "articles":
      if ($e_content == "推送网站目录") {
        $events = gz( $fromusername,$tousername);
      } else {
        $e_content = explode(",", $e_content);
        for ($i = 0;$i < count($e_content);$i++) {
          switch (substr($e_content[$i], 0, 1)) {
            case "t":
              if (getrs("select * from sl_text where t_id=" . substr($e_content[$i], -(strlen($e_content[$i]) - 1)), "t_title") != "") {
                $events = $events . "<item>
													<title><![cdata[" . lang(getrs("select * from sl_text where t_id=" . substr($e_content[$i], -(strlen($e_content[$i]) - 1)), "t_title")) . "]]></title>
													<description><![cdata[" . lang(getrs("select * from sl_text where t_id=" . substr($e_content[$i], -(strlen($e_content[$i]) - 1)), "t_description")) . "]]></description>
													<picurl><![cdata[http://" . $d_domain . "/" . getrs("select * from sl_text where t_id=" . substr($e_content[$i], -(strlen($e_content[$i]) - 1)), "t_pic") . "]]></picurl>
													<url><![cdata[http://" . $d_domain . "/wap_index.php?type=text&s_id=" . substr($e_content[$i], -(strlen($e_content[$i]) - 1)) . "]]></url>
													</item>";
              }
            break;
            case "n":
              if (getrs("select * from sl_news where n_id=" . substr($e_content[$i], -(strlen($e_content[$i]) - 1)), "n_title") != "") {
                $events = $events . "<item>
														<title><![cdata[" . lang(getrs("select * from sl_news where n_id=" . substr($e_content[$i], -(strlen($e_content[$i]) - 1)), "n_title")) . "]]></title>
														<description><![cdata[" . lang(getrs("select * from sl_news where n_id=" . substr($e_content[$i], -(strlen($e_content[$i]) - 1)), "n_short")) . "]]></description>
														<picurl><![cdata[http://" . $d_domain . "/" . getrs("select * from sl_news where n_id=" . substr($e_content[$i], -(strlen($e_content[$i]) - 1)), "n_pic") . "]]></picurl>
														<url><![cdata[http://" . $d_domain . "/wap_index.php?type=newsinfo&s_id=" . substr($e_content[$i], -(strlen($e_content[$i]) - 1)) . "]]></url>
														</item>";
              }
            break;
            case "p":
              if (getrs("select * from sl_product where p_id=" . substr($e_content[$i], -(strlen($e_content[$i]) - 1)), "p_title") != "") {
                $events = $events . "<item>
													<title><![cdata[" . lang(getrs("select * from sl_product where p_id=" . substr($e_content[$i], -(strlen($e_content[$i]) - 1)), "p_title")) . "]]></title>
													<description><![cdata[" . lang(getrs("select * from sl_product where p_id=" . substr($e_content[$i], -(strlen($e_content[$i]) - 1)), "p_short")) . "]]></description>
													<picurl><![cdata[http://" . $d_domain . "/" . splitx(splitx(getrs("select * from sl_product where p_id=" . substr($e_content[$i], -(strlen($e_content[$i]) - 1)), "p_path"), "|", 0),"_",0) . "]]></picurl>
													<url><![cdata[http://" . $d_domain . "/wap_index.php?type=productinfo&s_id=" . substr($e_content[$i], -(strlen($e_content[$i]) - 1)) . "]]></url>
													</item>";
              }
            break;
            case "f":
              if (getrs("select * from sl_form where f_id=" . substr($e_content[$i], -(strlen($e_content[$i]) - 1)), "f_title") != "") {
                $events = $events . "<item>
													<title><![cdata[" . lang(getrs("select * from sl_form where f_id=" . substr($e_content[$i], -(strlen($e_content[$i]) - 1)), "f_title")) . "]]></title>
													<description><![cdata[" . lang(getrs("select * from sl_form where f_id=" . substr($e_content[$i], -(strlen($e_content[$i]) - 1)), "f_description")) . "]]></description>
													<picurl><![cdata[http://" . $d_domain . "/" . getrs("select * from sl_form where f_id=" . substr($e_content[$i], -(strlen($e_content[$i]) - 1)), "f_pic") . "]]></picurl>
													<url><![cdata[http://" . $d_domain . "/wap_index.php?type=form&s_id=" . substr($e_content[$i], -(strlen($e_content[$i]) - 1)) . "]]></url>
													</item>";
              }
            break;
            case "c":
              $events = $events . "<item>
													<title><![cdata[联系我们]]></title>
													<description><![cdata[联系我们]]></description>
													<picurl><![cdata[http://" . $d_domain . "/" . $c_ico . "]]></picurl>
													<url><![cdata[http://" . $d_domain . "/wap_index.php?type=contact&s_id=1]]></url>
													</item>";
            break;
            case "g":
              $events = $events . "<item>
													<title><![cdata[在线留言]]></title>
													<description><![cdata[在线留言]]></description>
													<picurl><![cdata[http://" . $d_domain . "/" . $c_ico . "]]></picurl>
													<url><![cdata[http://" . $d_domain . "/wap_index.php?type=guestbook&s_id=1]]></url>
													</item>";
          }
        }
        
        if (strpos($events,"<title>")===false) {
          $events = "<item>
								<title><![cdata[文章已删除]]></title>
								<description><![cdata[文章已删除]]></description>
								<picurl><![cdata[http://" . $d_domain . "/" . $c_ico . "]]></picurl>
								<url><![cdata[http://" . $d_domain . "/wap_index.php]]></url>
								</item>";
          $num = 1;
        }else{
        	$num = count(explode("<title>", $events))-1;
        }

        $events = "<xml>
							<tousername><![cdata[" . $fromusername . "]]></tousername>
							<fromusername><![cdata[" . $tousername . "]]></fromusername>
							<createtime>" . date('y-m-d h:i:s') . "</createtime>
							<msgtype><![cdata[news]]></msgtype>
							<articlecount>" . $num . "</articlecount>
							<articles>" . $events . "</articles></xml>";
      }
  }
  file_put_contents("test2.txt", $events);
  return $events;
}
function text($fromusername, $tousername, $fromstr) {
  global $conn, $d_domain, $c_ico;
  $sql = "select * from sl_reply where r_key like '" . $fromstr . "'";
  $result = mysqli_query($conn, $sql);
  $row = mysqli_fetch_assoc($result);
  if (mysqli_num_rows($result) > 0) {
    $text = events( $fromusername,$tousername, "key_" . $row["r_reply"]);
  } else {
    $text = events( $fromusername,$tousername, "key_" . getrs("select * from sl_event where e_title like '未匹配到关键词'","e_id"));
  }
  return $text;
}
function gz($fromusername, $tousername) {
  global $conn, $d_domain, $c_ico;
  $sql2 = "select * from sl_slide order by s_id desc limit 1";
  $result2 = mysqli_query($conn, $sql2);
  $row2 = mysqli_fetch_assoc($result2);
  if (mysqli_num_rows($result2) > 0) {
    $s_pic = $row2["s_pic"];
  }
  $sql2 = "select count(*) as u_count from sl_menu where u_sub=0";
  $result2 = mysqli_query($conn, $sql2);
  $row2 = mysqli_fetch_assoc($result2);
  $u_count = $row2["u_count"];
  if ($u_count > 8) {
    $u_count = 8;
  }
  $gz = "<xml>
  <tousername><![cdata[" . $fromusername . "]]></tousername>
  <fromusername><![cdata[" . $tousername . "]]></fromusername>
  <createtime>" . date('y-m-d h:i:s') . "</createtime>
  <msgtype>news</msgtype>
  <articlecount>" . $u_count . "</articlecount>
  <articles>";
  $gz = $gz . "<item>
  <title>欢迎关注" . lang($c_webtitle) . "</title>
  <description>" . lang($c_webtitle) . "</description>
  <picurl><![cdata[http://" . $d_domain . "/" . $s_pic . "]]></picurl>
  <url><![cdata[http://" . $d_domain . "]]></url>
  </item>";
  $sql2 = "select * from sl_menu where u_sub=0 and not u_type='index' order by u_order limit " . ($u_count - 1) . "";
  $result2 = mysqli_query($conn, $sql2);
  if (mysqli_num_rows($result2) > 0) {
    while ($row2 = mysqli_fetch_assoc($result2)) {
      if ($row2["u_type"] != "sub" && $row2["u_type"] != "link") {
        $link = "wap_index.php?type=" . $row2["u_type"] . "&s_id=" . $row2["u_typeid"];
      } else {
        $link = $row2["u_link"];
      }
      $gz = $gz . "<item><title>" . lang($row2["u_title"]) . "/" . lang($row2["u_entitle"]) . "</title><description>" . lang($row2["u_title"]) . "/" . lang($row2["u_entitle"]) . "</description><picurl><![cdata[http://" . $d_domain . "/" . $c_ico . "]]></picurl><url><![cdata[http://" . $d_domain . "/" . $link . "]]></url></item>";
    }
    $gz = $gz . "</articles><funcflag>1</funcflag></xml>";
  }
  return $gz;
}
?>

以上所述是小编给大家介绍的php微商城代码详解整合,希望对大家有所帮助

上一篇:

下一篇: