在使用插件之前,请配置好交通银行在线支付的环境(具体安装方法,交行提供的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
因为公司要做一个项目活动在微信中要有这一样款游戏活动了,但自己不会写于是网上找到了一个作者写的方案下面我整理了一下可以用同时也分享给大家。
本来是不想写这篇博文的,但又怕网友被坑,我还是写一下。
下载 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最新版。
首页 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" width=100% 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'; } |
代码如下 | 复制代码 |
<?php curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $param['app_id'] = "app_id=x"; $data = "app_id=x&access_token={$access_token['access_token']}&token={$code}&phone=15091421612&url=http://wx.podapi.com/test.php&exp_time=2×tamp={$timestamp}&sign=".$sign; |