好友
阅读权限10
听众
最后登录1970-1-1
|
各位大大们,晚安.
小弟在理解的过程中遇到这一组函数,没办法理清是怎么达到的
这个函数是来自一个游戏的类似发送游戏道具至邮件的一个功能
因小弟因特殊要求需要把此函数用于ASP VB另作开发
所以想理清这个功能是怎么形成的.
[PHP] 纯文本查看 复制代码 <?php
error_reporting(0);
date_default_timezone_set("PRC");
session_start();
include '../../../../sdk/TPkgxml.php';
include '../common/conn.php';
if (isset($_POST)){
/*$connect = mysqli_connect("$ip","$ur","$pd",'yt_role') or die("数据库连接错误");
$role_id = $roleid % 64;
mysqli_query($connect, "set names utf8");
$sql='select `role_name`,`valid`,`level` from role_attrib_'.$role_id.' where qy_uin=?';
$stmt = $connect->prepare($sql);
$stmt->bind_param('s', $roleid);
$stmt->execute();
$result = $stmt->get_result();
if($result && $result->num_rows>0){
while($AccountInfo = mysqli_fetch_array($result)){
$_SESSION['csj_name'] = $AccountInfo['role_name'];
if($_SESSION['csj_name']!=null){
$zone = $AccountInfo['valid'];
$role_level = $AccountInfo['level'];
}else{
exit ("角色ID不存在,请联系管理员处理!";
}
}
}*/
$roleid = $_POST['roleid'];
$serverid = $_POST['serverid']; //区服id
$charid = $roleid; //角色id
$type = $_POST['type'];
switch ($type){
case 'charge':
if($charid>0){
$time=time();
$paykey='b3esEv$@k3a0mShwvo';
//$charid='10100359'; //角色id
$orderid='GMT'.($charid % 64).$time; //订单号
$itemid=$_POST['rid']; //礼包编码
$sign=md5($paykey.$charid.$serverid.$orderid.$itemid.$time.$paykey);
$data = array(
'charid' => $charid,
'orderid' =>$orderid,
'serverid' =>$serverid,
'itemid' => $itemid,
'tstamp' => $time,
'sign' => $sign
);
$pay_url="http://IP/pay.php?".http_build_query($data);
$ret = file_get_contents($pay_url);
if(isset($ret) || $ret==8){
exit('充值成功!');
}else{
exit('充值失败!');
}
}
break;
case 'mail':
$gmip='127.0.0.1';
$gmport='6001';
$cmd=8072;
$AgentSvrId=1101;
$accid=$charid;
$itemid=$_POST['itemid'];
$itemnum=$_POST['itemnum'];
$a=$charid % 64;
$connectc = mysqli_connect("$ip","$ur","$pd","$db") or die("数据库连接错误");
$stmtc = $connectc->prepare("select `qy_uin`,`role_id`,`role_name` from yt_role.role_attrib_{$a} where qy_uin=?");
$stmtc->bind_param('i', $charid);
$stmtc->bind_result($qy_uin,$role_id,$role_name);
$result=$stmtc->execute();
$row=$stmtc->fetch();
$parm2 = $itemid.'|'.$itemnum.'|0|'; // 物品id|数量|是否绑定(1绑定 0不绑定)
list($t1, $t2) = explode(' ', microtime());
$order = (float)sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000);
$goldnum=0;
$cause="长生诀Gm,祝你游戏愉快!!!";
$param6 = ''.time().'00000';
$str = "cuttle=".$cmd."&game_set_id=".$AgentSvrId."&parm0=".intval($accid)."&parm1=".intval($role_id)."&parm2=".$parm2."&parm3=".intval($order)."&parm4=".intval($goldnum)."&parm5=".$cause.'&parm6='.$param6;
$sign=md5($str.'malimalihong');
$str.="&sign=".$sign;
$pkg = new TPkgxmk($gmip, $gmport);
$pkg ->Endata($str);
$pkg->SendData();
$result[] = $pkg->getdata();
$xml_data = $pkg->DecodeXmlData();
$jsonStr = json_encode($xml_data);
$res = json_decode($jsonStr,true);
//usleep(100000);
if(isset($res['result']) || $res['result']==0){
exit('邮件发放成功!');
}else{
exit('邮件发放失败!');
}
}
}
?>
[PHP] 纯文本查看 复制代码 <?php
class TPkgxmk{
var $socket;
var $connection;
var $IP;
var $Port;
var $buffer;
var $buffer_len;
function __construct($IP,$Port){
$this->IP = $IP;
$this->Port = $Port;
$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)or die("Could not create socket\n");
$this->connection = socket_connect($this->socket, $this->IP, $this->Port) or die("Could not connet server\n");
}
function SendData(){
socket_write($this->socket, $this->buffer) or die("Write failed\n");
while ($this->buffer = socket_read($this->socket,65535,PHP_BINARY_READ)){
if(empty($this->buffer)) $i++;
if(empty($this->buffer) && $i==5){
exit('Could not read backdata');
}
$this->buffdata.=$this->buffer;
}
}
function SendDataNotWait(){
socket_write($this->socket, $this->buffer) or die("Write failed\n");
}
function Endata($data){
$head="POST /PostBulletin HTTP/1.1\r\n";
$head.="Connection:Close\r\nContent-Length:10\r\n\r\n";
$pre = $data."malimalihong";
$sign = md5($pre);
$data.="&sign=".$sign;
$this->buffer = $head.$data;
return $this->buffer;
}
function getdata($code="DECODE"){
if(!empty($this->buffdata)){
if($code=='DECODE'){
$result = str_replace("\n","<br />", htmlspecialchars($this->buffdata));
//$res = explode("<br /><br />", $result);
return $result;
}else{
// echo $this->buffdata;
return $this->buffdata;
}
}
}
function DecodeXmlData()
{
$content = substr($this->buffdata,strpos($this->buffdata, "<?xml"));
$data = simplexml_load_string($content);
return $data;
}
}
//����������
//$strs = "cuttle=8002&parm0=50054&parm1=7340036";
////$strs.="malimalihong";
////$sing = md5($strs);
////$strs.=$sing;
//$tp = new TPkgxmk("58.254.217.74", "6001");
//$tp->Endata($strs);
//$tp->SendData();
//$arr = $tp->getdata();
//$aa = str_replace("\n","<br />", htmlspecialchars($arr));
//
//echo $aa;
/*
<?php
$string ="
HTTP/1.1 200 OK
Date: Sat,14 Jun 2014 11:57:21 GMT
Server: QY1003
Content-Length: 101
Connection:close
Content-Type:text/xml
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<Response>
<result>0</result>
<cmd>8000</cmd>
<qy_name>kevin01</qy_name>
<qy_uin>10</qy_uin>
<role_id>12582913</role_id>
</Response>
";
$content = substr($string,strpos($string,"<?xml"));
$result = simplexml_load_string($content);
echo "result:".$result->result;
echo "</br>";
echo "cmd:".$result->cmd;
echo "</br>";
echo "qy_name:".$result->qy_name;
echo "</br>";
echo "qy_uin:".$result->qy_uin;
echo "</br>";
echo "role_id:".$result->role_id;
echo "</br>";
?>
*/
想请问这是以什么方式进行达到
如若小弟有遗漏函数,大大们可以指出 我可以提供相关文件代码.
感激不尽.
在线等待. |
|