no message

hotfix/远程访问多媒体中心
cyc 8 years ago
parent 943eb58e12
commit 182c358b9c

@ -1,5 +1,4 @@
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
//途牛apiurl
@ -15,13 +14,11 @@ class Tuniu_train extends CI_Controller{
// header("Content-Type: text/html;charset=utf-8");
parent::__construct();
date_default_timezone_set('PRC');
$this->load->helper('tuniu');
$this->load->library('Des');
$this->load->model("tuniuprice_model");
}
public function index(){
echo 'hello tuniu';
}
//创建请求签名
public function create_sign(){
$time = date('Y-m-d H:i:s',time());
@ -33,6 +30,11 @@ class Tuniu_train extends CI_Controller{
return strtoupper(md5($sign));
}
//index
public function index(){
echo 'hi,tuniu';
}
//获取余票
public function search($date,$fromStation,$toStation){
$sign = $this->create_sign();
@ -44,62 +46,87 @@ class Tuniu_train extends CI_Controller{
"timestamp": "'.$time.'",
"data": { "trainDate": "'.$date.'", "fromStation": "'.$fromStation.'", "toStation": "'.$toStation.'", "trainCode": "" }
}';
$back_data = $this->get_http($url,$post_data,$method = 'POST');
//print_r('返回码'.json_decode($back_data)->returnCode.'<br>');
$back_data = post_tuniu($url,$post_data,$method = 'POST');
//print_r($post_data);
//print_r(json_decode($back_data));
$return_data = new stdClass();
$return_data->returnCode = json_decode($back_data)->returnCode;
$return_data->httpstatus = 200;
$return_data->data = new stdClass();
$return_data->data->result = array();
$return_data->returnCode = json_decode($back_data)->returnCode;
$i = 0;
$pricestr = '';
foreach (json_decode($back_data)->data as $value){
$seat_type = '';
if(is_numeric($value->gjrwPrice)){
$gjrwPrice = $value->gjrwPrice * 10;
$seat_type .= '"6":"'.$gjrwPrice.'","A6":"¥'.$value->gjrwPrice.'",';
}
if(is_numeric($value->qtxbPrice)){
$seat_type .= '"H":"¥'.$value->qtxbPrice.'",';
}
if(is_numeric($value->rwPrice)){
$rwPrice = $value->rwPrice * 10;
$seat_type .= '"4":"'.$rwPrice.'","A4":"¥'.$value->rwPrice.'",';
}
if(is_numeric($value->rzPrice)){
$rzPrice = $value->rzPrice * 10;
$seat_type .= '"2":"'.$rzPrice.'","A2":"¥'.$value->rzPrice.'",';
}
if(is_numeric($value->tdzPrice)){
$seat_type .= '"P":"¥'.$value->tdzPrice.'",';
}
if(is_numeric($value->wzPrice)){
$wzPrice = $value->wzPrice * 10;
$seat_type .= '"WZ":"¥'.$value->wzPrice.'",';
}
if(is_numeric($value->ywPrice)){
$ywPrice = $value->ywPrice * 10;
$seat_type .= '"A3":"'.$ywPrice.'","3":"¥'.$value->ywPrice.'",';
}
if(is_numeric($value->yzPrice)){
$yzPrice = $value->yzPrice * 10;
$seat_type .= '"A1":"'.$yzPrice.'","1":"¥'.$value->yzPrice.'",';
}
if(is_numeric($value->edzPrice)){
$seat_type .= '"O":"¥'.$value->edzPrice.'",';
}
if(is_numeric($value->ydzPrice)){
$seat_type .= '"M":"¥'.$value->ydzPrice.'",';
}
if(is_numeric($value->swzPrice)){
$swzPrice = $value->swzPrice * 10;
$seat_type .= '"A9":"'.$swzPrice.'","9":"¥'.$value->swzPrice.'",';
if(!empty(json_decode($back_data)->data)){
foreach (json_decode($back_data)->data as $value){
$seat_type = '';
if(isset($value->gjrwPrice)){
if(is_numeric($value->gjrwPrice)){
$gjrwPrice = $value->gjrwPrice * 10;
$seat_type .= '"6":"'.$gjrwPrice.'","A6":"¥'.$value->gjrwPrice.'",';
}
}
if(isset($value->qtxbPrice)){
if(is_numeric($value->qtxbPrice)){
$seat_type .= '"H":"¥'.$value->qtxbPrice.'",';
}
}
if(isset($value->rwPrice)){
if(is_numeric($value->rwPrice)){
$rwPrice = $value->rwPrice * 10;
$seat_type .= '"4":"'.$rwPrice.'","A4":"¥'.$value->rwPrice.'",';
}
}
if(isset($value->rzPrice)){
if(is_numeric($value->rzPrice)){
$rzPrice = $value->rzPrice * 10;
$seat_type .= '"2":"'.$rzPrice.'","A2":"¥'.$value->rzPrice.'",';
}
}
if(isset($value->tdzPrice)){
if(is_numeric($value->tdzPrice)){
$seat_type .= '"P":"¥'.$value->tdzPrice.'",';
}
}
if(isset($value->wzPrice)){
if(is_numeric($value->wzPrice)){
$wzPrice = $value->wzPrice * 10;
$seat_type .= '"WZ":"¥'.$value->wzPrice.'",';
}
}
if(isset($value->ywPrice)){
if(is_numeric($value->ywPrice)){
$ywPrice = $value->ywPrice * 10;
$seat_type .= '"A3":"'.$ywPrice.'","3":"¥'.$value->ywPrice.'",';
}
}
if(isset($value->yzPrice)){
if(is_numeric($value->yzPrice)){
$yzPrice = $value->yzPrice * 10;
$seat_type .= '"A1":"'.$yzPrice.'","1":"¥'.$value->yzPrice.'",';
}
}
if(isset($value->edzPrice)){
if(is_numeric($value->edzPrice)){
$seat_type .= '"O":"¥'.$value->edzPrice.'",';
}
}
if(isset($value->ydzPrice)){
if(is_numeric($value->ydzPrice)){
$seat_type .= '"M":"¥'.$value->ydzPrice.'",';
}
}
if(isset($value->swzPrice)){
if(is_numeric($value->swzPrice)){
$swzPrice = $value->swzPrice * 10;
$seat_type .= '"A9":"'.$swzPrice.'","9":"¥'.$value->swzPrice.'",';
}
}
$pricestr = $seat_type.'"train_no":'.'"'.$value->trainNo.'"';
$return_data->data->result[$i] = '|预定|'.$value->trainNo.'|'.$value->trainCode.'|'.$value->fromStationName.'|'.$value->toStationName.'|'.$value->fromStationCode.'|'.$value->toStationCode.'|'.$value->startTime.'|'.$value->arriveTime.'|'.$value->runTime.'|'.$value->canBuyNow.'||'.date('Ymd',strtotime($value->trainStartDate)).'||||||||'.ticket_exchange($value->gjrwNum).'|'.ticket_exchange($value->qtxbNum).'|'.ticket_exchange($value->rwNum).'|'.ticket_exchange($value->rzNum).'|'.ticket_exchange($value->tdzNum).'|'.ticket_exchange($value->wzNum).'||'.ticket_exchange($value->ywNum).'|'.ticket_exchange($value->yzNum).'|'.ticket_exchange($value->edzNum).'|'.ticket_exchange($value->ydzNum).'|'.ticket_exchange($value->swzNum).'|'.ticket_exchange($value->dwNum).'||';
$i++;
$data = '{"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":{'.$pricestr.'},"messages":[],"validateMessages":{}}';
$this->tuniuprice_model->addOrUpdate($value->trainNo,$value->fromStationCode,$value->toStationCode,json_encode($data));
}
$pricestr = $seat_type.'"train_no":'.'"'.$value->trainNo.'"';
$return_data->data->result[$i] = '|预定|'.$value->trainNo.'|'.$value->trainCode.'|'.$value->fromStationName.'|'.$value->toStationName.'|'.$value->fromStationCode.'|'.$value->toStationCode.'|'.$value->startTime.'|'.$value->arriveTime.'|'.$value->runTime.'|'.$value->canBuyNow.'||'.$value->trainStartDate.'||||||||'.$value->gjrwNum.'|'.$value->qtxbNum.'|'.$value->rwNum.'|'.$value->rzNum.'|'.$value->tdzNum.'|'.$value->wzNum.'||'.$value->ywNum.'|'.$value->yzNum.'|'.$value->edzNum.'|'.$value->ydzNum.'|'.$value->swzNum.'|'.$value->dwNum.'||';
$i++;
$data = '{"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":{'.$pricestr.'},"messages":[],"validateMessages":{}}';
$this->tuniuprice_model->addOrUpdate($value->trainNo,$value->fromStationCode,$value->toStationCode,json_encode($data));
}
print_r(json_encode($return_data));
}
@ -117,21 +144,22 @@ class Tuniu_train extends CI_Controller{
//占座下单
public function book_ticket(){
header('Content-Type:application/json;charset=UTF-8');
$sign = $this->create_sign();
$url = TUNIU_URL.'/train/book';
$time = date('Y-m-d H:i:s',time());
$data = '{
"retailOrderId": "1",
"cheCi": "D2946",
"fromStationCode": "GLZ",
"fromStationName":"桂林",
"toStationCode":"GBZ",
"toStationName":"桂林北",
"trainDate""2017-09-23",
"retailOrderId": "w123",
"cheCi": "K1137",
"fromStationCode": "GBZ",
"fromStationName":"桂林",
"toStationCode":"NNZ",
"toStationName":"南宁",
"trainDate":"2017-09-25",
"callBackUrl":"http://www.mycht.cn/info.php/apps/train/tuniu_callback/book",
"hasSeat":true,
"contact":"陈宇超",
"phone":"18877381547",
"insureCode ":"",
"passengers":[{
"passengerId":1,
"ticketNo": null,
@ -141,129 +169,110 @@ class Tuniu_train extends CI_Controller{
"passportTypeName": "二代身份证",
"piaoType": "1",
"piaoTypeName": "成人票",
"zwCode": "O",
"zwName": "二等座",
"zwCode": "4",
"zwName": "软卧",
"cxin": null,
"price": "5.5",
"reason": 0,
"provinceCode": null,
"schoolCode": null,
"schoolName": null,
"studentNo": null,
"schoolSystem": null,
"enterYear": null,
"preferenceFromStationName": null,
"preferenceFromStationCode": null,
"preferenceToStationName": null,
"preferenceToStationCode": null
"price": "166.5",
"reason": 0
}]
}';
$crypt = new DES();
$mstr = $crypt->encrypt($data,TUNIU_KEY);
$post_data = '{
"apiKey": "'.TUNIU_KEY.'",
"sign": "'.$sign.'",
"timestamp": "'.$time.'",
"data": "'.$data.'"
"data": "'.$mstr.'"
}';
//print_r($url);
print_r($post_data);
//$back_data = $this->get_http($url,$post_data,$method = 'POST');
//print_r($back_data);
$back_data = post_tuniu($url,$post_data,$method = 'POST');
print_r($back_data);
}
//身份验证
public function validate(){
//$name = $this->input->post('name');
//$identityType = $this->input->post('identityType');
//$identifyCard = $this->input->post('identifyCard');
//取消占座
public function cancel_book($retailOrderId,$orderId){
$url = TUNIU_URL.'/train/cancel';
$sign = $this->create_sign();
$url = TUNIU_URL.'/train/validate';
$time = date('Y-m-d H:i:s',time());
$data =
$post_data = '{
"apiKey": "'.TUNIU_KEY.'",
"sign": "'.$sign.'",
"timestamp": "'.$time.'",
"data": { "name": "", "identityType": "", "identifyCard": ""}
"data": {
"retailOrderId":"'.$retailOrderId.'",
"orderId":"'.$orderId.'",
"callBackUrl":"http://www.mycht.cn/info.php/apps/train/tuniu_callback/cancelbook"
}
}';
$back_data = $this->get_http($url,$post_data,$method = 'POST');
print_r($back_data);
$back_data = post_tuniu($url,$post_data,$method = 'POST');
print_r($back_data);
}
public function des_encrypt() {
$this->load->library('Des');
$key = 'Te56CBQmorzJGeYIIK';
$str = '{
"retailOrderId": "452514",
"cheCi": "D2946",
"fromStationCode": "GLZ",
"fromStationName":"桂林",
"toStationCode":"GBZ",
"toStationName":"桂林北",
"trainDate":"2017-09-11",
"callBackUrl":"http://www.mycht.cn/info.php/apps/train/tuniu_callback/book",
"hasSeat":false,
"contact":"陈宇超",
"phone":"18877381547",
"insureCode ":"",
"passengers":[{
"passengerId":1,
"ticketNo": null,
//确认出票
public function confirm_ticket($retailOrderId,$orderId){
$url = TUNIU_URL.'/train/confirm';
$sign = $this->create_sign();
$time = date('Y-m-d H:i:s',time());
$post_data = '{
"apiKey": "'.TUNIU_KEY.'",
"sign": "'.$sign.'",
"timestamp": "'.$time.'",
"data": {
"retailOrderId":"'.$retailOrderId.'",
"orderId":"'.$orderId.'",
"callBackUrl":"http://www.mycht.cn/info.php/apps/train/tuniu_callback/confirm"
}
}';
$back_data = post_tuniu($url,$post_data,$method = 'POST');
print_r($back_data);
}
//退票
public function cancel_ticket($retailOrderId,$orderId){
$url = TUNIU_URL.'/train/return';
$sign = $this->create_sign();
$time = date('Y-m-d H:i:s',time());
$data = '{
"retailOrderId": "'.$retailOrderId.'",
"orderId": "'.$orderId.'",
"orderNumber": "E551561213",
"callBackUrl":"http://www.mycht.cn/info.php/apps/train/tuniu_callback/return_ticket",
"tickets":[{
"ticketNo": "TN_aaac40ec06d72851",
"passengerName": "陈宇超",
"passportNo": "450302199208131039",
"passportTypeId": "1",
"passportTypeName": "二代身份证",
"piaoType": "1",
"piaoTypeName": "成人票",
"zwCode": "O",
"zwName": "二等座",
"cxin": null,
"price": "5.5",
"reason": 0,
"provinceCode": null,
"schoolCode": null,
"schoolName": null,
"studentNo": null,
"schoolSystem": null,
"enterYear": null,
"preferenceFromStationName": null,
"preferenceFromStationCode": null,
"preferenceToStationName": null,
"preferenceToStationCode": null
"passportNo": "450302199208131039"
}]
}';
}';
$crypt = new DES();
$mstr = $crypt->encrypt($str,$key);
echo $mstr;
}
public function des_decrypt(){
echo base64_decode('JSh+QwFlC/uPYxpXDpx+g6LQ/82MAh3czFaFvSowBUt/A6LpIVPcNzYC5H8RpjlsGCQ67zcTJs6KA/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cFk+Ku4it0sI2XiO52+fML8BpggFMkoZXI6YP/KDoSNr/1XUWfWlTysVsREpGQh2b71GRJCzI8FUajTFEOQ+mKOWqzgGGzLbSfrK6aAZ2RIcEwNLkSIGdQTpxUuzVyUu7DCLqRbgaEC9bW8QmGowJj/8LdHbuno+JLNfUOQtCm7TVCLnWujTF1N5M+mKJuuv4kqIDIcoGWCauxf45dRRnr3ImAzi7Qpu01Qi51ro0xdTeTPpiibrr+JKiAyHKBlgmrsX+OX6ej4ks19Q5D+98vgpAT13mlSr0Q/lKffCXRX0VOdhhM=');
$mstr = $crypt->encrypt($data,TUNIU_KEY);
$post_data = '{
"apiKey": "'.TUNIU_KEY.'",
"sign": "'.$sign.'",
"timestamp": "'.$time.'",
"data": "'.$mstr.'"
}';
$back_data = post_tuniu($url,$post_data,$method = 'POST');
print_r($back_data);
}
//发送请求函数
public function get_http($url, $data = '', $method = 'GET') {
$curl = curl_init(); // 启动一个CURL会话
curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
if ($method == 'POST' && !empty($data)) {
curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
}
curl_setopt($curl, CURLOPT_TIMEOUT, 45); // 设置超时限制防止死循环
curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
$tmpInfo = curl_exec($curl); // 执行操作
$errno = curl_errno($curl);
if ($errno !== 0) {
return false;
echo $errno . curl_error($curl); //记录错误日志
}
curl_close($curl); //关闭CURL会话
return $tmpInfo; //返回数据
//身份验证
public function validate(){
//$name = $this->input->post('name');
//$identityType = $this->input->post('identityType');
//$identifyCard = $this->input->post('identifyCard');
$sign = $this->create_sign();
$url = TUNIU_URL.'/train/validate';
$time = date('Y-m-d H:i:s',time());
$post_data = '{
"apiKey": "'.TUNIU_KEY.'",
"sign": "'.$sign.'",
"timestamp": "'.$time.'",
"data": { "name": "", "identityType": "", "identifyCard": ""}
}';
$back_data = post_tuniu($url,$post_data,$method = 'POST');
print_r($back_data);
}
}

@ -0,0 +1,56 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//验证参数是否存在并且是否为数字
function checkNum($num){
if(isset($num)){
if(is_numeric($num)){
return true;
}else{
return false;
}
}else{
return false;
}
}
//余票转换
function ticket_exchange($num){
if(is_numeric($num)){
if($num == 0){
return '无';
}elseif($num == 99){
return '有';
}else{
return $num;
}
}
}
//发送请求函数
function post_tuniu($url, $data = '', $method = 'GET') {
$curl = curl_init(); // 启动一个CURL会话
curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
if ($method == 'POST' && !empty($data)) {
curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
}
curl_setopt($curl, CURLOPT_TIMEOUT, 45); // 设置超时限制防止死循环
curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
$tmpInfo = curl_exec($curl); // 执行操作
$errno = curl_errno($curl);
if ($errno !== 0) {
return false;
echo $errno . curl_error($curl); //记录错误日志
}
curl_close($curl); //关闭CURL会话
return $tmpInfo; //返回数据
}
?>

@ -5,7 +5,7 @@ class Des
function encrypt($string,$key)
{
$size = mcrypt_get_block_size('des', 'ecb');
$string = mb_convert_encoding($string, 'GBK', 'UTF-8');
//$string = mb_convert_encoding($string, 'GBK', 'UTF-8');
$string = $this->pkcs5_pad($string, $size);
$td = mcrypt_module_open('des', '', 'ecb', '');
$iv = @mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
@ -17,10 +17,9 @@ class Des
return $data;
}
function decrypt($string)
function decrypt($string,$key)
{
$string = base64_decode($string);
$key = $this->key;
$td = mcrypt_module_open('des', '', 'ecb', '');
//使用MCRYPT_DES算法,cbc模式
$iv = @mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);

Loading…
Cancel
Save