产品相册
对于地产、婚纱等行业来说,其产品经常是以大幅照片展示给用户,以视觉效果来吸引顾客来购买,对于这些行业的微信公众账号,我们可以开发一个相册功能。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>户型鉴赏</title>
<META charset=utf-8>
<meta name="author" content="Ste Brennan - Code Computerlove - http://www.codecomputerlove.com/" />
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<link href="css/styles.css" type="text/css" rel="stylesheet" />
<link href="css/photoswipe.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="js/klass.min.js"></script>
<script type="text/javascript" src="js/code.photoswipe-3.0.5.min.js"></script>
<script type="text/javascript">
(function(window, PhotoSwipe){
document.addEventListener('DOMContentLoaded', function(){
var options = {
preventHide: true,
getImageSource: function(obj){
return obj.url;
},
getImageCaption: function(obj){
return obj.caption;
}
},
instance = PhotoSwipe.attach(
[
{ url: 'imghx/image0132.jpg', caption: 'A户型 二室二厅一卫 80.07平方米'},
{ url: 'imghx/image0092.jpg', caption: 'B户型 二室二厅一卫 84.65平方米'},
{ url: 'imghx/image0032.jpg', caption: 'C户型 二室二厅二卫 103.89平方米'},
],
options
);
instance.show(0);
}, false);
}(window, window.Code.PhotoSwipe));
</script>
</head>
<body>
<script type="text/javascript">
document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
WeixinJSBridge.call('hideOptionMenu');
});
document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
WeixinJSBridge.call('hideToolbar');
});
</script>
</body>
</html>
jquery-mobile-2.html
<!DOCTYPE html>
<html>
<head>
<title>PhotoSwipe</title>
<link rel="stylesheet" href="../lib/jquery.mobile-1.0a4.1/jquery.mobile-1.0a4.1.min.css" />
<link href="../photoswipe.css" type="text/css" rel="stylesheet" />
<style type="text/css">
div.gallery-row:after { clear: both; content: "."; display: block; height: 0; visibility: hidden; }
div.gallery-item { float: left; width: 33.333333%; }
div.gallery-item a { display: block; margin: 5px; border: 1px solid #3c3c3c; }
div.gallery-item img { display: block; width: 100%; height: auto; }
#Gallery1 .ui-content, #Gallery2 .ui-content { overflow: hidden; }
</style>
<script type="text/javascript" src="../lib/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="../lib/jquery.mobile-1.0a4.1/jquery.mobile-1.0a4.1.min.js"></script>
<script type="text/javascript" src="../lib/simple-inheritance.min.js"></script>
<script type="text/javascript" src="../lib/jquery.animate-enhanced.min.js"></script>
<script type="text/javascript" src="../code-photoswipe-jQuery-1.0.11.min.js"></script>
<!-- <link href="css/styles.css" type="text/css" rel="stylesheet" />
<link href="css/photoswipe.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="js/klass.min.js"></script>
<script type="text/javascript" src="js/code.photoswipe-3.0.5.min.js"></script> -->
<script type="text/javascript">
/*
This example shows how to set up PhotoSwipe using jQuery Mobile.
*/
$(document).ready(function(){
$('div.gallery-page').live('pageshow', function(e){
// Re-initialize with the photos for the current page
$("div.gallery a", e.target).photoSwipe();
return true;
})
});
</script>
</head>
<body>
<div data-role="page" id="Gallery1" class="gallery-page">
<div data-role="content">
<div class="gallery">
<div class="gallery-row">
<div class="gallery-item"><a href="images/full/001.jpg" rel="external"><img src="images/thumb/001.jpg" alt="Image 001" width="30%" /></a></div>
<div class="gallery-item"><a href="images/full/002.jpg" rel="external"><img src="images/thumb/002.jpg" alt="Image 002" /></a></div>
<div class="gallery-item"><a href="images/full/003.jpg" rel="external"><img src="images/thumb/003.jpg" alt="Image 003" /></a></div>
</div>
<div class="gallery-row">
<div class="gallery-item"><a href="images/full/004.jpg" rel="external"><img src="images/thumb/004.jpg" alt="Image 004" /></a></div>
<div class="gallery-item"><a href="images/full/005.jpg" rel="external"><img src="images/thumb/005.jpg" alt="Image 005" /></a></div>
<div class="gallery-item"><a href="images/full/006.jpg" rel="external"><img src="images/thumb/006.jpg" alt="Image 006" /></a></div>
</div>
<div class="gallery-row">
<div class="gallery-item"><a href="images/full/007.jpg" rel="external"><img src="images/thumb/007.jpg" alt="Image 007" /></a></div>
<div class="gallery-item"><a href="images/full/008.jpg" rel="external"><img src="images/thumb/008.jpg" alt="Image 008" /></a></div>
<div class="gallery-item"><a href="images/full/009.jpg" rel="external"><img src="images/thumb/009.jpg" alt="Image 009" /></a></div>
</div>
<div class="gallery-row">
<div class="gallery-item"><a href="images/full/007.jpg" rel="external"><img src="images/thumb/007.jpg" alt="Image 007" /></a></div>
<div class="gallery-item"><a href="images/full/008.jpg" rel="external"><img src="images/thumb/008.jpg" alt="Image 008" /></a></div>
<div class="gallery-item"><a href="images/full/009.jpg" rel="external"><img src="images/thumb/009.jpg" alt="Image 009" /></a></div>
</div>
</div>
</div>
</div>
</body>
</html>
整体index.php代码如下:
<?php
/*
CopyRight 2018 All Rights Reserved
*/
define("TOKEN", "weixin");
$wechatObj = new wechatCallbackapiTest();
if (!isset($_GET['echostr'])) {
$wechatObj->responseMsg();
}else{
$wechatObj->valid();
}
class wechatCallbackapiTest
{
public function valid()
{
$echoStr = $_GET["echostr"];
if($this->checkSignature()){
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)){
$this->logger("R ".$postStr);
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$RX_TYPE = trim($postObj->MsgType);
switch ($RX_TYPE)
{
case "event":
$result = $this->receiveEvent($postObj);
break;
case "text":
$result = $this->receiveText($postObj);
break;
}
$this->logger("T ".$result);
echo $result;
}else {
echo "";
exit;
}
}
private function receiveEvent($object)
{
$content = "";
switch ($object->Event)
{
case "subscribe":
$content = "欢迎关注 德强1012 ";
break;
case "unsubscribe":
$content = "取消关注";
break;
}
$result = $this->transmitText($object, $content);
return $result;
}
private function receiveText($object)
{
$keyword = trim($object->Content);
$category = substr($keyword,0,6);
$code = trim(substr($keyword,6,strlen($keyword)));
switch ($category)
{
case "会员":
$content[] = array("Title" =>"会员卡",
"Description" =>"点击图片领取会员卡",
"PicUrl" =>"http://pic2.ooopic.com/01/38/77/75bOOOPICea.jpg",
"Url" =>"http://1.dq095.applinzi.com/91_membercard/member.php?openid=".$object->FromUserName);
break;http:
case "预约":
$content[] = array("Title" =>"预约口腔医生",
"Description" =>"点击图片开始预约",
"PicUrl" =>"http://pic4.nipic.com/20091021/3320206_171831027464_2.jpg",
"Url" =>"http://1.dq095.applinzi.com/92_order/order.php?openid=".$object->FromUserName);
break;
case "相册":
$content[] = array("Title" =>"产品相册",
"Description" =>"点击图片开始预约",
"PicUrl" =>"http://img2.imgtn.bdimg.com/it/u=3675030458,1339124782&fm=26&gp=0.jpg",
"Url" =>"//1.dq095.applinzi.com/93_album/1/huxing.php");
break;
case "照片":
$content[] = array("Title" =>"产品相册",
"Description" =>"点击图片开始预约",
"PicUrl" =>"http://pic.90sjimg.com/back_pic/u/00/02/82/06/561c95213aaa4.jpg",
"Url" =>"http://1.dq095.applinzi.com/93_album/2/examples/jquery-mobile-2.html");
break;
default:
$content = "";
break;
}
if(is_array($content)){
$result = $this->transmitNews($object, $content);
}else{
$result = $this->transmitText($object, $content);
}
return $result;
}
private function transmitText($object, $content)
{
$textTpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[%s]]></Content>
</xml>";
$result = sprintf($textTpl, $object->FromUserName, $object->ToUserName, time(), $content);
return $result;
}
private function transmitNews($object, $arr_item)
{
if(!is_array($arr_item))
return;
$itemTpl = " <item>
<Title><![CDATA[%s]]></Title>
<Description><![CDATA[%s]]></Description>
<PicUrl><![CDATA[%s]]></PicUrl>
<Url><![CDATA[%s]]></Url>
</item>
";
$item_str = "";
foreach ($arr_item as $item)
$item_str .= sprintf($itemTpl, $item['Title'], $item['Description'], $item['PicUrl'], $item['Url']);
$newsTpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[news]]></MsgType>
<Content><![CDATA[]]></Content>
<ArticleCount>%s</ArticleCount>
<Articles>
$item_str</Articles>
</xml>";
$result = sprintf($newsTpl, $object->FromUserName, $object->ToUserName, time(), count($arr_item));
return $result;
}
private function logger($log_content)
{
}
}
?>