WeMall的Android app商城中的wemall doraemon代码
生活随笔
收集整理的這篇文章主要介紹了
WeMall的Android app商城中的wemall doraemon代码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
WeMall-Android
包含SMSSDK/WeMall-Client/social_sdk_library_project三個項目以及Api目錄下的client.php/update.xml接口文件,其中WeMall-Client依賴于項目SMSSDK、social_sdk_library_project
使用指南:本客戶端是WeMall開源微信商城的Android版,首先需要您部署WeMall微信商城才能使用,使用方法如下
一:安裝wemall微信商城篇
(1):將WeMall-Server項目(WeMall開源商城)安裝到您的Web服務器,測試環境這里推薦使用wamp環境,快捷部署
(2):wemall微信商城安裝完畢后將Api目錄下的client.php和update.xml接口文件復制到WeMall開源商城Web服務器的Api目錄下
二:導入客戶端代碼并編譯生成自己的版本篇
(1):將SMSSDK/social_sdk_library_project項目導入到你的IDE(Eclipse或者Android Studio)
(2):將WeMall-Client項目導入到你的IDE,然后需要可能會報錯,這里重新配置項目依賴,依賴于SMSSDK/social_sdk_library_project
(3):修改WeMall-Client項目源碼中的Myconfig.java,將服務端地址設置為你們的WeMall微信商城地址
(4):配置完畢后即可測試運行wemall安卓客戶端了
(5):當客戶端編譯新的版本時,將apk上傳到服務器后配置Api/update.xml文件即可,當用戶檢測新版本時,即可收到新的版本提示信息
注1:本客戶端兼容Wemall微信商城3.x版本,只要WeMall商城安裝正常,Api目錄下的文件上傳到服務器指定地址,客戶端即可正常訪問
注2:直接下載客戶端源代碼打包也可運行客戶端,默認接入我的演示服務端
注3:第一次分享項目,第一次寫Android應用,技術不精,說的不明白的可聯系QQ793554262,閑暇時間可以交流咨詢
附加信息
演示服務端地址www.uaide.net/wemall/
測試管理員admin密碼admin,請不要隨意刪除服務器已存在數據
client.php
<span style="font-weight: normal;"><?php
///
/**********************************************
WeMall客戶端Api,劉德位編寫
Bug反饋QQ:793554262
**********************************************/
///
header("Content-type:text/html;charset=utf-8");
global $_SERVER;
$agent = $_SERVER['HTTP_USER_AGENT'];
if($agent!="WeMall_Client"){echo "非法請求";exit();
}
?>
<?php
//sql注入過濾-by360
function customError($errno, $errstr, $errfile, $errline)
{ echo "Error number:[$errno],error on line $errline in $errfile";die();
}
set_error_handler("customError",E_ERROR);
$getfilter="'|(and|or)\\b.+?(>|<|=|in|like)|\\/\\*.+?\\*\\/|<\\s*script\\b|\\bEXEC\\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\\s+(TABLE|DATABASE)";
$postfilter="\\b(and|or)\\b.{1,6}?(=|>|<|\\bin\\b|\\blike\\b)|\\/\\*.+?\\*\\/|<\\s*script\\b|\\bEXEC\\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\\s+(TABLE|DATABASE)";
$cookiefilter="\\b(and|or)\\b.{1,6}?(=|>|<|\\bin\\b|\\blike\\b)|\\/\\*.+?\\*\\/|<\\s*script\\b|\\bEXEC\\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\\s+(TABLE|DATABASE)";
function StopAttack($StrFiltKey,$StrFiltValue,$ArrFiltReq){ if(is_array($StrFiltValue))
{$StrFiltValue=implode($StrFiltValue);
}
if (preg_match("/".$ArrFiltReq."/is",$StrFiltValue)==1){ print "非法請求";exit();
}
} foreach($_GET as $key=>$value){ StopAttack($key,$value,$getfilter);
}
foreach($_POST as $key=>$value){ StopAttack($key,$value,$postfilter);
}
foreach($_COOKIE as $key=>$value){ StopAttack($key,$value,$cookiefilter);
}?>
<?php include('../Public/Conf/config.php');?>
<?php$tag=$_GET['tag'];
if(!isset($_GET['tag'])){echo "非法請求";}
else{switch ($tag) {case 'wemall_query_myorder':wemall_query_myorder();break;case 'wemall_update_myadder':wemall_update_myadder();break;case 'wemall_query_goods':wemall_query_goods();break;case 'wemall_add_order':wemall_add_order();break;case 'wemall_update_passwd':wemall_update_passwd();break;case 'wemall_update_head':wemall_update_head();break;case 'wemall_login_check':wemall_login_check();break;case 'wemall_rec_passwd':wemall_rec_passwd();break;case 'wemall_user_regist':wemall_user_regist();break;case 'wemall_query_menu':wemall_query_menu();break;default:echo "非法請求";break;}
}
?>
<?php
//訂單查詢@@@
function wemall_query_myorder(){$uid=$_POST['uid'];//uidecho "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";echo "<root>\n";if (isset($_POST['uid'])){$result = @mysql_query("select * from ".DB_PREFIX."order where user_id=(select id from ".DB_PREFIX."user where uid='$uid') order by time desc") or die("錯誤,請重試");while ($row=mysql_fetch_array($result)) {echo "<orders id=\"".$row[id]."\">"."<orderid>".$row[orderid]."</orderid>"."<totalprice>".$row[totalprice]."</totalprice>"."<pay_style>".$row[pay_style]."</pay_style>"."<pay_status>".$row[pay_status]."</pay_status>"."<note>".$row[note]."</note>"."<order_status>".$row[order_states]."</order_status>"."<time>".$row[time]."</time>"."<cartdata>".$row[cartdata]."</cartdata></orders>\n";}}echo "</root>";
}
//更新用戶收貨地址
function wemall_update_myadder(){$uid=$_POST['uid'];$address=base64_decode($_POST['address']);if (isset($_POST['uid'])&&isset($_POST['address'])){$result =@mysql_query("select uid from ".DB_PREFIX."user where uid='$uid' limit 1") or die("");if (mysql_num_rows($result)==0){echo "0";}elseif (mysql_num_rows($result)==1){@mysql_query("update ".DB_PREFIX."user set address='$address' where uid='$uid'") or die("");echo "1";}}else{echo "非法請求";}
}
//查詢商品
function wemall_query_goods(){$preg = "/<\/?[^>]+>/i";//正則表達式,剔除詳情里的html標簽$type=$_POST['type'];//分類標志if (isset($_POST['type'])){$sql = "select * from ".DB_PREFIX."good where menu_id='$type' and status=1";}else{$sql = "select * from ".DB_PREFIX."good where status=1";}$result = mysql_query($sql);echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";echo "<items>\n";while ($row=mysql_fetch_array($result)) {echo "<item id=\"$row[id]\">"."<typeid>".$row[menu_id]."</typeid>"."<name>".$row[name]."</name>"."<image>".$row[image]."</image>"."<intro>".str_replace(' ','',preg_replace($preg,'',$row[detail]))."</intro>"."<price>".$row[price]."</price>"."<priceno>".$row[old_price]."</priceno>"."</item>\n";}echo "</items>";
}
//增加訂單
function wemall_add_order(){$uid=$_POST['uid'];$totalprice=$_POST['totalprice'];$paystyle=$_POST['paystyle'];$paystatus=$_POST['paystatus'];$note=$_POST['note'];$cartdata =$_POST['cartdata'];$orderid=date("YmdHis").get_millisecond();$userid=null;//獲取userid$sql = "select id from ".DB_PREFIX."user where uid='$uid'";$result = mysql_query($sql);while ($row=mysql_fetch_array($result)) {$userid=$row['id'];}//校驗并插入訂單if(isset($_POST['uid'])){$sql = "insert into ".DB_PREFIX."order (id,user_id,orderid,totalprice,pay_style,pay_status,note,order_status,time,cartdata) values(NULL,'$userid','$orderid','$totalprice','$paystyle','$paystatus','$note',0,CURRENT_TIMESTAMP,'$cartdata')";mysql_query($sql);echo $sql;}else{echo "非法請求";}
}
//設置密碼
function wemall_update_passwd(){$uid=$_POST['uid'];$oldusersubmit=md5($_POST['old']);$new=md5($_POST['new']);if (isset($_POST['uid'])&&isset($_POST['old'])&&isset($_POST['new'])){$result =@ mysql_query("select password from ".DB_PREFIX."user where uid='$uid' limit 1") or die("");while ($row=@mysql_fetch_array($result)) {if($row['password']!=$oldusersubmit){echo "0";}else if($row['password']==$oldusersubmit){$result=@mysql_query("update ".DB_PREFIX."user set password='$new' where uid='$uid' limit 1") or die("");echo "1";}}}else{echo "非法請求";}
}
//更新頭像
function wemall_update_head(){if(isset($_POST['photo'])&&isset($_POST['uid'])){ $file =fopen('./uploads/'.(md5($_POST['uid'])).'.jpg', "w");fwrite($file,base64_decode($_POST['photo']));fclose($file);}else{echo "非法請求";}
}
function wemall_login_check(){$account=$_POST['account'];//帳號$passwd=md5($_POST['passwd']);//密碼if (isset($_POST['account'])){$result = @mysql_query("select * from ".DB_PREFIX."user where phone='$account' limit 1") or die("錯誤,請重試");if (mysql_num_rows($result)==0){echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";echo "<root>\n";echo "<result state=\"-1\"><uid></uid><name></name><phone></phone><address></address></result>\n";echo "</root>";}else{while ($row=mysql_fetch_array($result)) {if($row['password']==$passwd){echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";echo "<root>\n";echo "<result state=\"1\">"."<uid>".$row[uid]."</uid>"."<name>".$row[username]."</name>"."<phone>".$row[phone]."</phone>"."<address>".$row[address]."</address></result>\n";echo "</root>";}else{echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";echo "<root>\n";echo "<result state=\"0\"><uid></uid><name></name><phone></phone><address></address></result>\n";echo "</root>";}}}}
}
//恢復密碼
function wemall_rec_passwd(){$phone=$_POST['phone'];$new=md5($_POST['new']);if (isset($_POST['phone'])&&isset($_POST['new'])){$result =@mysql_query("select phone from ".DB_PREFIX."user where phone='$phone' limit 1") or die("");if (mysql_num_rows($result)==0){echo "0";}elseif(mysql_num_rows($result)==1){$result=@mysql_query("update ".DB_PREFIX."user set password='$new' where phone='$phone' limit 1") or die("");echo "1";}}else{echo "非法請求";}
}
//注冊用戶
function wemall_user_regist(){$phone=$_POST['phone'];$name=base64_decode($_POST['name']);$saltuid=getRandStr($length=10);$uid=md5($_POST['phone'].$saltuid); //給用戶構造一個唯一的UID,這里我們使用手機號加10位隨機字符串的md5作為生成方案$passwd=md5($_POST['passwd']);if (isset($_POST['phone'])&&isset($_POST['name'])&&isset($_POST['passwd'])){$result =@ mysql_query("select uid from ".DB_PREFIX."user where phone='$phone'") or die("");if (mysql_num_rows($result)>0){echo "0";}elseif (mysql_num_rows($result)==0){$result=@mysql_query("insert into ".DB_PREFIX."user(uid,username,password,phone) values('$uid','$name','$passwd','$phone')") or die("");echo "1";}}else{echo "非法請求";}
}
//查詢分組
function wemall_query_menu(){$sql = "select * from ".DB_PREFIX."menu order by id asc";$result = mysql_query($sql);echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";echo "<types>\n";while ($row=mysql_fetch_array($result)) {echo "<type id=\"$row[id]\">"."<name>".$row[name]."</name></type>\n";}echo "</types>";
}
/世界你好
function getRandStr($length) { $str = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';$randString ='';$len = strlen($str)-1;for($i = 0;$i < $length;$i ++){$num = mt_rand(0, $len);$randString .= $str[$num];}return $randString ;
}
function get_millisecond(){list($usec, $sec) = explode(" ", microtime());$msec=round($usec*1000);return $msec; }
?></span>
?
代碼詳情
頁面顯示:http://www.koahub.com/home/product/55
碼云代碼:http://git.oschina.net/zzunet/wemall-doraemon
總結
以上是生活随笔為你收集整理的WeMall的Android app商城中的wemall doraemon代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 三星S6E换电池记
- 下一篇: 200条装修小常识(2)