吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1121|回复: 1
收起左侧

[求助] 关于PHP的函数

[复制链接]
jetyao95 发表于 2020-3-31 20:34
各位大大们,晚安.
小弟在理解的过程中遇到这一组函数,没办法理清是怎么达到的
这个函数是来自一个游戏的类似发送游戏道具至邮件的一个功能
因小弟因特殊要求需要把此函数用于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;
	}
}
//&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;
//$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>";

?>
*/



想请问这是以什么方式进行达到
如若小弟有遗漏函数,大大们可以指出 我可以提供相关文件代码.

感激不尽.

在线等待.

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

唯一丶 发表于 2020-4-1 17:43
第一个主要只是一个分支,流程控制,
第二个就是一个发送 POST 的,发送的是 XML 他这里复杂化了。
http://58.254.217.74:6001/PostBulletin 发送了一个 POST 请求,

待发送的数据
cuttle=8002&parm0=50054&parm1=7340036
计算签名,即拼接上密钥 malimalihong,并进行 md5 处理
sign = md5("cuttle=8002&parm0=50054&parm1=7340036malimalihong")
这里 sign 计算出来的结果是 faa6b12356d3d5f9da7e8fe13f54e7db
最终就是向 http://58.254.217.74:6001/PostBulletin 发送了一个数据,内容是 cuttle=8002&parm0=50054&parm1=7340036&sign=faa6b12356d3d5f9da7e8fe13f54e7db ,
最终收到结果


这个 58.254.217.74:6001 目前连不上~
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-26 18:28

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表