正在显示
1 个修改的文件
包含
59 行增加
和
1 行删除
@@ -83,7 +83,6 @@ class PayController extends WeChatBaseController | @@ -83,7 +83,6 @@ class PayController extends WeChatBaseController | ||
83 | if ($order['status']==1) { // 假设订单字段“支付时间”不为空代表已经支付 | 83 | if ($order['status']==1) { // 假设订单字段“支付时间”不为空代表已经支付 |
84 | return true; // 已经支付成功了就不再更新了 | 84 | return true; // 已经支付成功了就不再更新了 |
85 | } | 85 | } |
86 | -// | ||
87 | // // 用户是否支付成功 | 86 | // // 用户是否支付成功 |
88 | if ($successful) { | 87 | if ($successful) { |
89 | // 回填微信的订单号 | 88 | // 回填微信的订单号 |
@@ -91,6 +90,9 @@ class PayController extends WeChatBaseController | @@ -91,6 +90,9 @@ class PayController extends WeChatBaseController | ||
91 | // $update['pay_time']=time(); | 90 | // $update['pay_time']=time(); |
92 | // 不是已经支付状态则修改为已经支付状态 | 91 | // 不是已经支付状态则修改为已经支付状态 |
93 | $update['status']=1; | 92 | $update['status']=1; |
93 | + $light=Db::name('light_order')->where('order_sn',$out_trade_no)->find(); | ||
94 | + //硬件控制 | ||
95 | +// $this->lightChange($light['light_id'],'01','01',$light['name']); | ||
94 | } else { // 用户支付失败 | 96 | } else { // 用户支付失败 |
95 | $update['status']=0; | 97 | $update['status']=0; |
96 | } | 98 | } |
@@ -103,6 +105,62 @@ class PayController extends WeChatBaseController | @@ -103,6 +105,62 @@ class PayController extends WeChatBaseController | ||
103 | } | 105 | } |
104 | 106 | ||
105 | 107 | ||
108 | + protected function lightChange($id="",$status1='01',$status2='01',$u=""){ | ||
109 | + if ($id==""){ | ||
110 | + return false; | ||
111 | + }else { | ||
112 | + $light=Db::name('light')->where('id',$id)->find(); | ||
113 | + $client = fsockopen('114.215.223.17', 5002, $errno, $errmsg, 1); | ||
114 | + $code=$light['addr'].'10000000102001'.$light['addr'].$status1.$status2.$this->strtoascii($u).'00'; | ||
115 | + $crc=$this->crc16_modbus($code); | ||
116 | + $changeCode=$code.substr($crc,2,2).substr($crc,0,2); | ||
117 | +// var_dump($queryCode); | ||
118 | + $data = array('uid' => $light['number'], 'percent' => "$changeCode"); | ||
119 | + // 发送数据,注意5678端口是Text协议的端口,Text协议需要在数据末尾加上换行符 | ||
120 | + fwrite($client, json_encode($data) . "\n"); | ||
121 | + // 读取推送结果 | ||
122 | + return fread($client, 8192); | ||
123 | + } | ||
124 | + } | ||
125 | + | ||
126 | + function crc16_modbus($msg) | ||
127 | + { | ||
128 | + $data = pack('H*',$msg); | ||
129 | + $crc = 0xFFFF; | ||
130 | + for ($i = 0; $i < strlen($data); $i++) | ||
131 | + { | ||
132 | + $crc ^=ord($data[$i]); | ||
133 | + | ||
134 | + for ($j = 8; $j !=0; $j--) | ||
135 | + { | ||
136 | + if (($crc & 0x0001) !=0) | ||
137 | + { | ||
138 | + $crc >>= 1; | ||
139 | + $crc ^= 0xA001; | ||
140 | + } | ||
141 | + else $crc >>= 1; | ||
142 | + } | ||
143 | + } | ||
144 | + return sprintf('%04X', $crc); | ||
145 | + } | ||
146 | + public function strtoascii($str="潘浩文") | ||
147 | + { | ||
148 | + $str = mb_convert_encoding($str, 'GB2312'); | ||
149 | + $change_after = ''; | ||
150 | + for ($i = 0; $i < strlen($str); $i=$i+2) { | ||
151 | + $change_after .= dechex(ord($str[$i])).dechex(ord($str[$i+1])); | ||
152 | + } | ||
153 | + for ($i=0;strlen($change_after)<52;$i++){ | ||
154 | + $change_after=$change_after.'00'; | ||
155 | + } | ||
156 | + return strtoupper($change_after); | ||
157 | + } | ||
158 | + | ||
159 | + | ||
160 | + | ||
161 | + | ||
162 | + | ||
163 | + | ||
106 | /** | 164 | /** |
107 | * 查询订单 | 165 | * 查询订单 |
108 | */ | 166 | */ |
-
请 注册 或 登录 后发表评论