Ejemplo n.º 1
0
 public function notify()
 {
     $notify = new \Org\Wechat\WxPay();
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     if ($notify->checkSign() == FALSE) {
         $notify->setReturnParameter("return_code", "FAIL");
         //返回状态码
         $notify->setReturnParameter("return_msg", "签名失败");
         //返回信息
     } else {
         $notify->setReturnParameter("return_code", "SUCCESS");
         //设置返回码
     }
     $returnXml = $notify->returnXml();
     $data = $notify->getData();
     if ($data['return_code'] == 'SUCCESS') {
         if ($data['result_code'] == 'SUCCESS') {
             // 确认收款
             $map['trade'] = $data['out_trade_no'];
             $order = M('UserOrder')->where($map)->find();
             if ($order != null && $order['payment'] == 0) {
                 $order['payment'] = $data['total_fee'];
                 M('UserOrder')->save($order);
                 D('UserOrder')->createOrderItem($order);
                 $weObj = new \Org\Wechat\Wechat(C('WECHAT'));
                 /* $message['touser'] = $order['openId']; */
                 /* $message['msgtype'] = 'text'; */
                 /* $message['text'] = array('content' => "您已预定水果成功"); */
                 /* $weObj->sendCustomMessage($message); */
                 $location = M('Location')->find($order['locationId']);
                 $message['touser'] = $order['openId'];
                 $message['template_id'] = 'gEdLfypbMwa-c3mLb2-aCxOFMz9OGI-565k718QGt0c';
                 $message['url'] = 'http://www.meirixianguo.com/wechat/wxpay/order?showwxpaytitle=1';
                 $message['topcolor'] = '#00FF00';
                 $message['data']['first'] = array('value' => urlencode('您已成功预定果大侠产品'), 'color' => '#000000');
                 $message['data']['product'] = array('value' => '果大侠整果', 'color' => '#000000');
                 $message['data']['price'] = array('value' => $order['payment'] / 100 . '元', 'color' => '#000000');
                 $message['data']['time'] = array('value' => $order['cdate'], 'color' => '#000000');
                 $message['data']['remark'] = array('value' => urlencode('\\n记得在下个工作日及时取回水果哦,还能分享给好友,一起开启健康生活!\\n取货地点:' . $location['name']), 'color' => '#FF8715');
                 $weObj->sendTemplateMessage($message);
                 // 销毁代金券
                 if (isset($data['attach'])) {
                     M('UserVoucher')->where('id=' . $data['attach'])->setField('valid', 0);
                     unset($message);
                     $message['touser'] = $order['openId'];
                     $message['template_id'] = '2W160vGYDJmucz17GtSs-wTTXnXghpmGQCmx5RCTCgI';
                     $message['url'] = 'http://www.meirixianguo.com/wechat/wxpay/order?showwxpaytitle=1';
                     $message['topcolor'] = '#00FF00';
                     $message['data']['first'] = array('value' => urlencode('您已经成功消费了一个果大侠代金券!'), 'color' => '#000000');
                     $message['data']['keyword1'] = array('value' => 100000 + $order['id'], 'color' => '#000000');
                     $message['data']['keyword2'] = array('value' => $data['total_fee'] / 100 . '元', 'color' => '#000000');
                     $message['data']['keyword3'] = array('value' => '果大侠4.89元代金券', 'color' => '#000000');
                     $message['data']['keyword4'] = array('value' => 100000 + $data['attach'], 'color' => '#000000');
                     $message['data']['keyword5'] = array('value' => date('Y-m-d'), 'color' => '#000000');
                     $message['data']['remark'] = array('value' => urlencode('\\n急需预定水果,还能分享给好友,一起开启健康生活!'), 'color' => '#FF8715');
                     $weObj->sendTemplateMessage($message);
                 }
             }
         }
     }
     echo $returnXml;
 }
Ejemplo n.º 2
0
 public function notify()
 {
     $notify = new \Org\Wechat\WxPay();
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     if ($notify->checkSign() == FALSE) {
         $notify->setReturnParameter("return_code", "FAIL");
         //返回状态码
         $notify->setReturnParameter("return_msg", "签名失败");
         //返回信息
     } else {
         $notify->setReturnParameter("return_code", "SUCCESS");
         //设置返回码
     }
     $returnXml = $notify->returnXml();
     $data = $notify->getData();
     if ($data['return_code'] == 'SUCCESS') {
         if ($data['result_code'] == 'SUCCESS') {
             $order = M('Order')->find($data['attach']);
             if ($order != null && $order['payment'] == 0) {
                 $order['payment'] = $data['total_fee'];
                 M('Order')->save($order);
                 M('OrderItem')->where('orderId=' . $order['id'])->setField(array('status' => 1));
             }
         }
     }
     echo $returnXml;
 }