微信公共账号营销工具 刮刮乐的开发
本来是不想写这篇博文的,但又怕网友被坑,我还是写一下。
下载 jquery扩展wScratchPad.js, 原站的页面打不开,我这里提供一个下载地址 http://file.111cn.net/upload/2014/4/wScratchPad-1.4.4.zip
然后(冷静),一些没节操的博主,直接转别人的文章,验证的过程都省了,应该坑了不是小白。我这里修正一下
在这个扩展里面,怎么才能过去用户的刮开的面积
$("#wScratchPad3").wScratchPad({
cursor:'', //设置鼠标的样式
color:'gray' , //设置覆盖物的颜色,跟image2功能相斥
width:"300",
height:"100",
image: "" //顶部的图片
// 更多配置相关的选项请看源码
scratchUp: function(e, percent){
if(percent > 60)
{
alert("sss");
}
}
});
从上面的代码,看的出来,这个跟网上所谓的教程不一样,这里获取刮开的范围用到函数不是
scratchMove()
而是
scratchUp()
为嘛?看源码
scratchFunc: function(e, $this, event)
{
e.pageX = Math.floor(e.pageX - $this.canvas_offset.left);
e.pageY = Math.floor(e.pageY - $this.canvas_offset.top);
$this['scratch' + event](e, $this);
if(this.settings.realtimePercent || event == "Up") {
if($this.settings['scratch' + event]) $this.settings['scratch' + event].apply($this, [e, $this.scratchPercentage($this)]);
}
}
这里这个获取函数绑定的UP 而不是move
注意这里的wScratchPad是1.4.4最新版。
1、需要设置一个 TOKEN 信息
代码如下 | 复制代码 |
efine("TOKEN", "weixin"); |
这个 TOKEN 信息可以由开发者自行设定。
2、有个 wechatCallbackapiTest 类,该类中含有3个方法:valid、responseMsg、checkSignature,其中方法valid、checkSignature是用作验证接口URL有效性用的,responseMsg是我们使用最多的方法,后续大部分的开发工作都会在这里完成。
在我们对接口进行有效性验证通过后,就不再需要进行验证了,这时我们就需要使用到 responseMsg 方法。那么如何保证接口验证通过后,不需要去切换其中的方法或修改其中的代码呢?
我是这样做的:
代码如下 | 复制代码 |
public function indexAction() //valid signature , option return FALSE; |
讲解一下:
因为在验证接口有效性时传递了个 echostr 参数,而在消息接口响应过程中没有这个参数,所有我们这里用这个参数来判断是验证接口还是接口响应:
代码如下 | 复制代码 |
isset($_GET['echostr']) |
在使用插件之前,请配置好交通银行在线支付的环境(具体安装方法,交行提供的demo会有,也不是很难,注意好细节就行)。安装好之后,请将includes文件夹和languages文件夹拷贝到ecshop站点的根目录覆盖(最下面有源码下载),最后进入后台的支付模块安装即可。
以下是调用的范例:
代码如下 | 复制代码 |
$order_['orderid'] = $order['order_sn']; $order_['amount'] = $order['yd_price']; $order_['orderMono'] = '测试'; //商家备注 $order_['goodsURL'] = "http://".$_SERVER['HTTP_HOST'].'/respond.php?code=bankcomm'; //取货URL $pay_code = new bankcomm; $pay_button = $pay_code->get_code($order_); $order['pay_button'] = $pay_button; //即此时已经生成了一个支付按钮 |
源码(includes/modules/payment/bankcomm.php):
代码如下 | 复制代码 |
<?php
* 交通银行在线支付插件 For Ecshop * Author: Reson * Date: 2014/03/31 */
{ die('Hacking attempt'); }
{ global $_LANG; include_once($payment_lang); }
if (isset($set_modules) && $set_modules == TRUE) { $i = isset($modules) ? count($modules) : 0;
$modules[$i]['code'] = basename(__FILE__, '.php');
$modules[$i]['desc'] = 'bankcomm_desc';
$modules[$i]['is_cod'] = '0';
$modules[$i]['is_online'] = '1';
$modules[$i]['pay_fee'] = '0';
$modules[$i]['author'] = 'Reson';
$modules[$i]['website'] = 'http://www.daixiaorui.com';
$modules[$i]['version'] = '1.0.0.0';
$modules[$i]['config'] = array(); return; }
* 类 */ class bankcomm { /** * 构造函数 * * @return void */ function bankcomm() { }
{ $this->bankcomm(); }
* 提交函数 */ function get_code($order) { //获得表单传过来的数据 $param['interfaceVersion'] = '1.0.0.0'; //消息版本号* $param['merID'] = '301310063009501'; //商户号 (测试号,后期可自行更改) $param['orderid'] = $order['orderid']; //订单号* $param['orderDate'] = local_date("Ymd",gmtime()); //商户订单日期* yyyyMMdd $param['orderTime'] = local_date("His",gmtime()); //商户订单时间* HHmmss $param['tranType'] = 0; //交易类别* 0:B2C $param['amount'] = $order['amount']; //订单金额* $param['curType'] = 'CNY'; //交易币种* 默认CNY $param['orderContent'] = ''; $param['orderMono'] = $order['orderMono']; //商家备注 $param['phdFlag'] = ''; //物流配送标志 $param['notifyType'] = 1; //通知方式* 1 通知 $param['merURL'] = ''; $param['goodsURL'] = $order['goodsURL']; //取货URL $param['jumpSeconds'] = ''; $param['payBatchNo'] = ''; $param['proxyMerName'] = ''; $param['proxyMerType'] = ''; $param['proxyMerCredentials'] = ''; $param['netType'] = 0; //渠道编号* 0:html渠道 $param['issBankNo'] = ''; $tranCode = "cb2200_sign";
//连接字符串 $source = ''; foreach($param as $key=>$val){ if($key != 'issBankNo') $source .= $val.'|'; } $source = substr($source,0,strlen($source)-1);
$socketUrl = "tcp://127.0.0.1:8080"; //这里的端口根据自己配置的情况 $fp = stream_socket_client($socketUrl, $errno, $errstr, 30); $retMsg=""; // if (!$fp) { echo "$errstr ($errno)<br /> "; } else { $in = "<?xml version='1.0' encoding='UTF-8'?>"; $in .= "<Message>"; $in .= "<TranCode>".$tranCode."</TranCode>"; $in .= "<MsgContent>".$source."</MsgContent>"; $in .= "</Message>"; fwrite($fp, $in); while (!feof($fp)) { $retMsg =$retMsg.fgets($fp, 1024); } fclose($fp); } //解析返回xml $dom = new DOMDocument; $dom->loadXML($retMsg); $retCode = $dom->getElementsByTagName('retCode'); $retCode_value = $retCode->item(0)->nodeValue; $errMsg = $dom->getElementsByTagName('errMsg'); $errMsg_value = $errMsg->item(0)->nodeValue; $signMsg = $dom->getElementsByTagName('signMsg'); $signMsg_value = $signMsg->item(0)->nodeValue; $orderUrl = $dom->getElementsByTagName('orderUrl'); $orderUrl_value = $orderUrl->item(0)->nodeValue; $MerchID = $dom->getElementsByTagName('MerchID'); $merID = $MerchID->item(0)->nodeValue; //echo "retMsg=".$retMsg; //echo $retCode_value." ".$errMsg_value." ".$signMsg_value." ".$orderUrl_value; if($retCode_value != "0"){ //echo "交易返回码:".$retCode_value."<br>"; //echo "交易错误信息:" .$errMsg_value."<br>"; return "交易错误信息:" .$errMsg_value."<br>"; }else{ $param['signMsg_value'] = $signMsg_value; $param['orderUrl_value'] = $orderUrl_value; $form_code = $this->create_html($param); //创建提交表单 return $form_code; } } /** * 创建提交表单 */ function create_html($param){ $pay_html ='<form name = "form1" method = "post" action = "'.$param['orderUrl_value'].'"> <input type = "hidden" name = "interfaceVersion" value = "'.$param['interfaceVersion'].'"> <input type = "hidden" name = "merID" value = "'.$param['merID'].'"> <input type = "hidden" name = "orderid" value = "'.$param['orderid'].'"> <input type = "hidden" name = "orderDate" value = "'.$param['orderDate'].'"> <input type = "hidden" name = "orderTime" value = "'.$param['orderTime'].'"> <input type = "hidden" name = "tranType" value = "'.$param['tranType'].'"> <input type = "hidden" name = "amount" value = "'.$param['amount'].'"> <input type = "hidden" name = "curType" value = "'.$param['curType'].'"> <input type = "hidden" name = "orderContent" value = "'.$param['orderContent'].'"> <input type = "hidden" name = "orderMono" value = "'.$param['orderMono'].'"> <input type = "hidden" name = "phdFlag" value = "'.$param['phdFlag'].'"> <input type = "hidden" name = "notifyType" value = "'.$param['notifyType'].'"> <input type = "hidden" name = "merURL" value = "'.$param['merURL'].'"> <input type = "hidden" name = "goodsURL" value = "'.$param['goodsURL'].'"> <input type = "hidden" name = "jumpSeconds" value = "'.$param['jumpSeconds'].'"> <input type = "hidden" name = "payBatchNo" value = "'.$param['payBatchNo'].'"> <input type = "hidden" name = "proxyMerName" value = "'.$param['proxyMerName'].'"> <input type = "hidden" name = "proxyMerType" value = "'.$param['proxyMerType'].'"> <input type = "hidden" name = "proxyMerCredentials" value = "'.$param['proxyMerCredentials'].'"> <input type = "hidden" name = "netType" value = "'.$param['netType'].'"> <input type = "hidden" name = "merSignMsg" value = "'.$param['signMsg_value'].'"> <input type = "hidden" name = "issBankNo" value = "'.$param['issBankNo'].'"> <input type="submit" value=" " class="pay_button" /> </form>'; return $pay_html; }
* 处理函数 */ function respond() { $tranCode = "cb2200_verify"; $notifyMsg = $_REQUEST["notifyMsg"]; $lastIndex = strripos($notifyMsg,"|"); $signMsg = substr($notifyMsg,$lastIndex+1); //签名信息 $srcMsg = substr($notifyMsg,0,$lastIndex+1);//原文 //连接地址 $socketUrl = "tcp://127.0.0.1:8080"; $fp = stream_socket_client($socketUrl, $errno, $errstr, 30); $retMsg=""; if (!$fp) { //echo "$errstr ($errno)<br /> "; return false; }else{ $in = "<?xml version='1.0' encoding='UTF-8'?>"; $in .= "<Message>"; $in .= "<TranCode>".$tranCode."</TranCode>"; $in .= "<MsgContent>".$notifyMsg."</MsgContent>"; $in .= "</Message>"; fwrite($fp, $in); while (!feof($fp)) { $retMsg =$retMsg.fgets($fp, 1024); } fclose($fp); } //解析返回xml $dom = new DOMDocument; $dom->loadXML($retMsg); $retCode = $dom->getElementsByTagName('retCode'); $retCode_value = $retCode->item(0)->nodeValue; $errMsg = $dom->getElementsByTagName('errMsg'); $errMsg_value = $errMsg->item(0)->nodeValue; $signMsg = $dom->getElementsByTagName('signMsg'); $signMsg_value = $signMsg->item(0)->nodeValue; if($retCode_value != ''){ //echo "交易返回码:".$retCode_value."<br>"; //echo "交易错误信息:" .$errMsg_value."<br>"; return false; }else{ $arr = preg_split("/|{1,}/",$srcMsg); $pay_id = $arr[1]; $action_note = base64_decode($arr[16]); // 完成订单。 order_paid($pay_id, PS_PAYED, $action_note); //告诉用户交易完成 return true; } ///////////////// respond END /////////////// } }
* 交通银行语言文件 * by: Reson www.111cn.net * 2014/03/31 */
$_LANG['bankcomm_desc'] = '交通银行在线支付'; $_LANG['pay_button'] = '交通银行支付';
|
原文件址:http://www.daixiaorui.com/read/80.html
原文下载:http://file.111cn.net/upload/2014/4/13962827995368.zip
这是一个可以获取网页的html代码以及css,js,font和img资源的小工具,主要用来快速获取模板。如果你来不及设计UI或者看到不错的模板,则可以使用这个工具来抓取网页和提取资源文件。提取的内容会按相对路径来保存资源,因此你不必担心资源文件的错误url导入
首页 index.php:
代码如下 | 复制代码 |
<!DOCTYPE html> |
抓取页面代码 grab.php:
代码如下 | 复制代码 |
<?PHP if(isset($_POST['url'])) { function grab($url) { if(($content = file_get_contents($url)) !== false) { if(isset($_POST['project'])) file_put_contents($_POST['project'].'/'.$file, $content); $pattern = '/<link.*?href=('|")(.*?.css)1.*?>/i'; $pattern = '/<script.*?src=('|")(.*?.js)1.*?>/i'; $pattern = '/<img.*?src=('|")(.*?)1.*?>/i'; $pattern = '/url(('|"|s)(.*?)1)/i'; return $data; www.111cn.net function vardump($obj) { |
保存css,js,img等资源的页面 save.php:
代码如下 | 复制代码 |
<?PHP if(isset($_POST['url']) && isset($_POST['project']) && isset($_POST['domain'])) { if($domain == 'http') { |
使用方法:
1. 打开index页,输入项目名和要抓取的网址,网址必须是文件名结尾,如index.html;
2. 点Get按钮,得到当前页面所有的css,js,img等资源列表;
3. 点击css链接会获取css文件中的背景资源图片,附加在列表后头;
4. 点击Save All即可保存列表中所有的文件,并按相对路径生成;
5. 如果网页上有http远程文件,将会直接保存在http文件夹下;
6. Get和Save有时会失败,没关系重试几次即可。
html:
代码如下 | 复制代码 |
<form action=”insertPic.php” method=”post” enctype=”multipart/form-data” name=”mainForm” id=”mainForm”> <input type=”file” name=”myFile” /> <input type=”submit” name=”Submit” value=”Submit”/> </form> |
将图片保存到数据库:
代码如下 | 复制代码 |
<?php //由于上传过来的图片被保存在一个临时文件中,所以 //我们仅需要读取该文件就可以获取传过来的图片 $fp = fopen($_FILES["myFile"]["tmp_name"],”rb”); $buf = addslashes(fread($fp,$_FILES["myFile"]["size"])); //创建一个PDO对象 $dbh = new PDO(“mysql:host=localhost;port= 3306;dbname=test”, “root”, “123456″); //执行插入操作并将结果保存在一个变量中 $result = $dbh->query(“INSERT INTO img (images) VALUES (‘$buf’)”); //获取影响的行数 if ($result->rowCount() >0) { echo(“数据已插入。”); } else { echo(“不能执行插入操作。”); } //显式的关闭PDO连接 $dbh = NULL; ?> 显示图片:(show.php) <?php $conn=@mysql_connect(“localhost”,”root”,”123456″) or die(“服务器连接错误!”); //链接数据库 @mysql_select_db(“test”,$conn) or die(“未发现数据库!”); $query=”select * from img where Id=”.$_GET['id']; $result=mysql_query($query); www.111cn.net $num=mysql_num_rows($result); $data = mysql_result($result,0,”images”); header(“Content-type: image/” . $num['imgType']); echo $data; ?> |
或者
代码如下 | 复制代码 |
<img src=”show.php?id=5″ /> |
1、fopen函数。
fopen()函数用于打开文件或者URL。语法如下:
int fopen(string filename, string mode);
字符串参数mode可以是下列的情形:
“r”开文件方式为只读,文件指针指到开始处。
“r+”开文件方式为可读写,文件指针指到开始处。
“w”开文件方式为写入,文件指针指到开始处,并将原文件的长度设为0。若文件不存在,则建立新文件。
“w+”开文件方式为可读写,文件指针指到开始处,并将原文件的长度设为0。若文件不存在,则建立新文件。
“a”开文件方式为写入,文件指针指到文件最后。若文件不存在,则建立新文件。
“a+”开文件方式为可读写,文件指针指到文件最后。若文件不存在,则建立新文件。
“b”若操作系统的文字及二进位文件不同,则可以用此参数,UNIX系统不需要使用本参数。
2、Addslashes函数。
Addslashes函数用于将字符串加入斜线。语法如下:【注:我测试的时候是把这个函数去掉后成功了,道理你懂的。自己试下就明白了】
string addslashes(string str);
该函数使需要让数据库处理的字符串,引号的部份加上斜线,以供数据库查询(query)能顺利运作。这些会被改的字符包括单引号(’)、双引号(”)、反斜线backslash()以及空字符NULL(the null byte)。
3、fread函数。
fread函数用于读到指定长度的位组或到文件尾EOF。语法如下:
string fread(int fp, int length);可安全用于二进制文件
fread() 从文件指针 file 读取最多 length 个字节。该函数在读取完最多 length 个字节数,或到达 EOF 的时候,或(对于网络流)当一个包可用时,或(在打开用户空间流之后)已读取了 8192 个字节时就会停止读取文件,视乎先碰到哪种情况。
二进制转换成图片
注:$newFilePath 对生成的图片名和路径做处理,这里自己去实现。
代码如下 | 复制代码 |
$newFilePath='1.jpg'; $data = $GLOBALS[HTTP_RAW_POST_DATA];//得到post过来的二进制原始数据 if(empty($data)){ www.111cn.net $data=file_get_contents("php://input"); } $newFile = fopen($newFilePath,"w");//打开文件准备写入 fwrite($newFile,$data);//写入二进制流到文件 fclose($newFile);//关闭文件 |
可以把读取到的二进制流存到数据库,也可以直接写入成一个图片。
获取二进制头文件,从而得知属于什么类型文件
代码如下 | 复制代码 |
$bin = substr($content,0,2); $strInfo = @unpack("C2chars", $bin); $typeCode = intval($strInfo['chars1'].$strInfo['chars2']); $fileType = ''; switch ($typeCode) { case 7790: $fileType = 'exe'; break; case 7784: $fileType = 'midi'; break; case 8297: $fileType = 'rar'; break; case 255216: $fileType = 'jpg'; break; case 7173: $fileType = 'gif'; break; case 6677: $fileType = 'bmp'; break; case 13780: $fileType = 'png'; break; default: echo 'unknown'; } |
相关文章
- 这篇文章主要为大家详细介绍了C#微信开发之发送模板消息的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-06-25
- 这篇文章主要介绍了iOS新版微信底部返回横条问题的解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-06-30
- 为公司系统业务需要,这几天了解了一下微信和支付宝扫码支付的接口,并用c#实现了微信和支付宝扫码支付的功能。需要的朋友跟随小编一起看看吧...2020-06-25
- 这篇文章主要介绍了Python爬取微信小程序通用方法代码实例详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-09-29
- 这篇文章主要介绍了C#实现的微信网页授权操作逻辑封装,分析了微信网页授权操作的原理、步骤并给出了C#实现的网页授权操作逻辑封装类,需要的朋友可以参考下...2020-06-25
- 这篇文章主要介绍了iOS新版微信底部工具栏遮挡问题完美解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-06-30
- 这篇文章主要为大家详细介绍了C#图像识别,微信跳一跳机器人,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-06-25
- 这篇文章主要介绍了简单用VBS调用企业微信机器人发定时消息的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-12-08
- 这篇文章主要介绍了python实现企业微信定时发送文本消息的实例代码,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-11-25
- 六月才刚刚过半,就已经相继有中兴、华为被美国起诉,此次微信也未能幸免,被美国一家叫Uniloc的公司起诉,理由是微信的语音群聊、视频聊天等功能侵犯其两项与电话会议技术相关的专利,该公司要求微信立即中止这些功能。...2016-07-04
- 这篇文章主要为大家详细介绍了原生JS实现微信通讯录,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-06-19
- 这篇文章主要介绍了HTML5实现微信拍摄上传照片功能,实现HTML5 Canvas手机拍摄,本地压缩上传图片时遇到问题的解决方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2017-04-27
- 这篇文章主要介绍了解决微信授权成功后点击按返回键出现空白页和报错的问题,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-06-08
- 这篇文章主要介绍了使用JavaScript脚本判断网页是否在微信中被打开的方法,在各种使用微信参加活动的移动版页面上经常可以用到,需要的朋友可以参考下...2016-03-09
JavaScript结合Bootstrap仿微信后台多图文界面管理
这篇文章主要为大家详细介绍了js结合Bootstrap仿微信后台多图文界面管理,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2016-07-29- 这篇文章主要介绍了利用aotu.js实现微信自动添加通讯录中的联系人,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-05-28
- 有很多人在做微信的扫一扫下载。但是在微信更新之后微信将该功能给禁止掉了,也不能说是全面禁止吧,因为腾讯、微信是一家嘛,通过应用宝审核的应用好像还是可以通过扫一扫直接下载的,下面通过本篇文章给大家介绍微信扫一扫下载app的代码片段,感兴趣的朋友一起看看吧...2016-01-02
- 这篇文章主要介绍了JS实现微信 "炸屎"大作战,本文通过实例代码图文展示给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-07-30
- 这篇文章主要为大家详细介绍了JavaScript仿微信打飞机游戏的相关代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2017-05-09
- 这篇文章主要介绍了Swift仿微信语音通话最小化时后的效果的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-03-04