http://1.rose111.applinzi.com/guirenli(建议微信手机端访问)
责任:
新浪云数据库建表,查询
1.通过PHP获取用户的ip地址,处理form表单提交的数据
2.mysql数据库插入,查询并返回指定用户
3.用户关注公众号后,公众号推送游戏链接
process_form.php
<?php
//领取一束
$hostname = SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT;
$dbuser = SAE_MYSQL_USER;
$dbpass = SAE_MYSQL_PASS;
$dbname = SAE_MYSQL_DB;
$link = mysql_connect($hostname, $dbuser, $dbpass);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
//echo 'Connected successfully<br/>';
//select db
mysql_select_db($dbname, $link) or die ('Can\'t use dbname : ' . mysql_error());
//echo 'Select db '.$dbname.' successfully';
mysql_close($link);
// create short variable names
$user_name=$_POST['user_name'];
$phone=$_POST['phone'];
$address=$_POST['address'];
$postcode=$_POST['postcode'];
if (!$user_name || !$phone || !$address ) {
echo "You have not entered all the required details.<br />"
."Please go back and try again.";
exit;
}
if (!get_magic_quotes_gpc()) {
$user_name = addslashes($user_name);
$phone = addslashes($phone);
$address = addslashes($address);
$postcode = doubleval($postcode);
}
$mysql = new SaeMysql();
//@ $db = new SaeMysql("SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS,app_meltykiss");
//@ $db = new mysqli('localhost', 'root', '', 'books');
// if (mysqli_connect_errno()) {
// echo "Error: Could not connect to database. Please try again later.";
// exit;
//}
$sql= "insert into user (user_name,phone,address,postcode) values
('".$user_name."', '".$phone."', '".$address."', '".$postcode."')";
$result = $mysql->runSql($sql);
$mysql->closeDb();
if ($result) {
echo "<img src=\"images/submit_success.png\" alt=\"success\" style=\"position: absolute; top:23.67%; left:2%;
width: 100%;height:80% \"/>";
} else {
echo "<table class=\"table table-striped\"><tr>
<td class=\"info\">An error has occurred. The item can not be repeated.</td></tr></table>";
}
?>
订阅关注微信号:推送游戏链接
<html>
<script src="js/jquery-2.1.4.js" type="text/javascript"></script>
<script src="js/app.js"></script>
<script type="text/javascript">
function test() {
window.totalAmount = parseInt(window.totalAmount) + 500 ;
window.View.saveStorage(5,parseInt(window.totalAmount));
window.countTotalAmount.text(parseInt(window.totalAmount));
}
</script>
<?php
/*** wechat php test */
//define your token
define("TOKEN", "weixin");
$wechatObj = new wechatCallbackapiTest();
if (isset($_GET['echostr'])) {
$wechatObj->valid();
}else{
$wechatObj->responseMsg();
}
class wechatCallbackapiTest
{
public function valid()
{
$echoStr = $_GET["echostr"];
if($this->checkSignature()){
ob_clean();
echo $echoStr;
exit;
}
}
private function checkSignature()
{
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = TOKEN;
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}
public function responseMsg()
{
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
if (!empty($postStr)){
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$fromUsername = $postObj->FromUserName;
$toUsername = $postObj->ToUserName;
$keyword = trim($postObj->Content);
$time = time();
$textTpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Content><![CDATA[%s]]></Content>
<FuncFlag>0</FuncFlag>
</xml>";
if($keyword == "?" || $keyword == "?")
{
$msgType = "text";
$contentStr = date("Y-m-d H:i:s",time());
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
echo $resultStr;
}
}else{
echo "";
exit;
}
}
}
?>
获取用户ip
<html>
<body>
<?php
@ $db = new SaeMysql("SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS,app_rose111");
if (mysqli_connect_errno()) {
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
$value=8;
$sql = "select * from ordersip where orderid like '%".$value."%'";
//$sql="select * from table1 where field1 like ’%value1%’ ";
//$sql = "select * from ordersip limit 6,1 ";
$result = $db->getData($sql);
if($result){
?>
<br/>
<br/>
<?php
foreach($result as $small){
$ip = $answer.$small['ip']; //获取符合搜索要求的记录的字段
$orderid = $answer.$small['orderid'];
echo $ip;
echo"<br/>";
echo $orderid;
}
}
?>
<script>
var b=<?php echo $orderid; ?>
alert (b);
</script>
</body>
</html>