public function run()
 {
     $post_str = file_get_contents("php://input", true);
     $post_obj = simplexml_load_string($post_str, 'SimpleXMLElement', LIBXML_NOCDATA);
     if (isset($post_obj->return_code)) {
         $result_code = $post_obj->result_code;
         $return_code = $post_obj->return_code;
         $out_trade_no = $post_obj->out_trade_no;
         $payOrder = PayMentORM::where('out_trade_no', '=', $out_trade_no)->first();
         if (!empty($payOrder)) {
             $payOrder->notify_time = date("Y-m-d H:i:s", time());
             $payOrder->result_code = $result_code;
             $payOrder->return_code = $return_code;
             $payOrder->save();
         }
         if ($result_code == "SUCCESS" || $return_code == "SUCCESS") {
             $payOrder->transaction_id = $post_obj->transaction_id;
             $payOrder->time_end = $post_obj->time_end;
             $payOrder->server_paid = 1;
             $payOrder->save();
             //更新订单
             $order = OrderORM::whereId($payOrder->order_id)->first();
             $order->pay_status = 1;
             $order->save();
         }
         echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
     } else {
         echo '<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[ERROR_MSG]]></return_msg></xml>';
     }
     exit;
 }
示例#2
0
 public function run()
 {
     $order_id = Input::get('order_id', 0);
     $user_id = Input::get('user_id', 0);
     $open_id = Input::get('open_id', '');
     $pay_ment = PayMentORM::whereOrderId($order_id)->where('openid', '<>', '')->first();
     if (empty($pay_ment)) {
         $order = OrderORM::whereId($order_id)->wherePayStatus(BaseORM::DISABLE)->first();
         if (empty($order)) {
             return '订单未找到';
         }
         if ($user_id != $order->user_id) {
             return '用户不正确';
         }
         $album = AlbumORM::whereId($order->album_id)->first();
         if (empty($album)) {
             return '相册未找到';
         }
         $template = TemplateORM::whereId($album->template_id)->first();
         if (empty($template)) {
             return '相册模版未找到';
         }
         $params['out_trade_no'] = $this->_generate_out_trade_no($order_id, $user_id);
         $params['subject'] = '购买相册打印服务';
         $params['quantity'] = $order->quantity;
         $params['total_fee'] = $order->total_amount;
         $params['price'] = $template->price;
         $params['body'] = '购买相册打印服务';
         $params['user_id'] = $user_id;
         $params['openid'] = $open_id;
         $params['order_id'] = $order_id;
         $r = PayMentORM::edit(0, $params);
         $pay_ment = $r[1];
     }
     try {
         $m = new Wxpay();
         $jsParameters = $m->getJsApiParameters($pay_ment->out_trade_no, $pay_ment->total_fee * 100, $pay_ment->openid);
         return json_decode($jsParameters, true);
     } catch (Exception $e) {
         return '内部错误';
     }
 }