...
|
...
|
@@ -116,9 +116,7 @@ class PayController extends WeChatBaseController |
|
|
// cache('nnn',111);
|
|
|
$app = new Application($this->options);
|
|
|
$response = $app->payment->handleNotify(function($notify, $successful){
|
|
|
|
|
|
/*这里是支付回调逻辑处理,一下是DEMO*/
|
|
|
|
|
|
// // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
|
|
|
$out_trade_no=$notify->out_trade_no;
|
|
|
$order = Db::name('light_order')->where('order_sn',$out_trade_no)->find();
|
...
|
...
|
@@ -141,13 +139,28 @@ class PayController extends WeChatBaseController |
|
|
//硬件控制
|
|
|
Db::name('light_order')->where('order_sn',$out_trade_no)->update(['status'=>1,'pay_time'=>time()]);
|
|
|
$this->lightChange($order['light_id'],'01','01',$order['name'],$order['content']);
|
|
|
//支付成功推送模板消息
|
|
|
$app = new Application($this->options);
|
|
|
$notice = $app->notice;
|
|
|
$userId = Db::name('users')->where('id',$order['users_id'])->find()['open_id'];
|
|
|
$templateId = 'ngqIpbwh8bUfcSsECmogfXcV14J0tQlEpBO27izEYtY';
|
|
|
$url = '';
|
|
|
$data = array(
|
|
|
"first" => "恭喜你购买成功!",
|
|
|
"name" => "巧克力",
|
|
|
"price" => "39.8元",
|
|
|
"remark" => "欢迎再次购买!",
|
|
|
);
|
|
|
|
|
|
$result = $notice->uses($templateId)->withUrl($url)->andData($data)->andReceiver($userId)->send();
|
|
|
|
|
|
|
|
|
} else {
|
|
|
// 用户支付失败
|
|
|
Db::name('light_order')->where('order_sn',$out_trade_no)->delete();
|
|
|
}
|
|
|
return true; // 返回处理完成
|
|
|
});
|
|
|
|
|
|
$response->send();
|
|
|
}
|
|
|
|
...
|
...
|
@@ -230,9 +243,17 @@ class PayController extends WeChatBaseController |
|
|
public function strtoascii1($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]));
|
|
|
if(strlen($str)%2!=0){
|
|
|
$change_after = '';
|
|
|
for ($i = 0; $i < strlen($str); $i = $i + 1) {
|
|
|
$change_after .= dechex(ord($str[$i]));
|
|
|
// var_dump($change_after);
|
|
|
}
|
|
|
}else {
|
|
|
$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)<50;$i++){
|
|
|
$change_after=$change_after.'00';
|
...
|
...
|
|