作者 潘浩文
1 个管道 的构建 通过 耗费 0 秒

订单渲染

... ... @@ -83,7 +83,6 @@ class PayController extends WeChatBaseController
if ($order['status']==1) { // 假设订单字段“支付时间”不为空代表已经支付
return true; // 已经支付成功了就不再更新了
}
//
// // 用户是否支付成功
if ($successful) {
// 回填微信的订单号
... ... @@ -91,6 +90,9 @@ class PayController extends WeChatBaseController
// $update['pay_time']=time();
// 不是已经支付状态则修改为已经支付状态
$update['status']=1;
$light=Db::name('light_order')->where('order_sn',$out_trade_no)->find();
//硬件控制
// $this->lightChange($light['light_id'],'01','01',$light['name']);
} else { // 用户支付失败
$update['status']=0;
}
... ... @@ -103,6 +105,62 @@ class PayController extends WeChatBaseController
}
protected function lightChange($id="",$status1='01',$status2='01',$u=""){
if ($id==""){
return false;
}else {
$light=Db::name('light')->where('id',$id)->find();
$client = fsockopen('114.215.223.17', 5002, $errno, $errmsg, 1);
$code=$light['addr'].'10000000102001'.$light['addr'].$status1.$status2.$this->strtoascii($u).'00';
$crc=$this->crc16_modbus($code);
$changeCode=$code.substr($crc,2,2).substr($crc,0,2);
// var_dump($queryCode);
$data = array('uid' => $light['number'], 'percent' => "$changeCode");
// 发送数据,注意5678端口是Text协议的端口,Text协议需要在数据末尾加上换行符
fwrite($client, json_encode($data) . "\n");
// 读取推送结果
return fread($client, 8192);
}
}
function crc16_modbus($msg)
{
$data = pack('H*',$msg);
$crc = 0xFFFF;
for ($i = 0; $i < strlen($data); $i++)
{
$crc ^=ord($data[$i]);
for ($j = 8; $j !=0; $j--)
{
if (($crc & 0x0001) !=0)
{
$crc >>= 1;
$crc ^= 0xA001;
}
else $crc >>= 1;
}
}
return sprintf('%04X', $crc);
}
public function strtoascii($str="潘浩文")
{
$str = mb_convert_encoding($str, 'GB2312');
$change_after = '';
for ($i = 0; $i < strlen($str); $i=$i+2) {
$change_after .= dechex(ord($str[$i])).dechex(ord($str[$i+1]));
}
for ($i=0;strlen($change_after)<52;$i++){
$change_after=$change_after.'00';
}
return strtoupper($change_after);
}
/**
* 查询订单
*/
... ...