public function wxpay_app()
 {
     $period_id = Input::get('period_id');
     $period = Period::find($period_id);
     // 判断时间段有效性
     if (!isset($period)) {
         return Response::json(array('error_code' => 2, 'message' => '无该时间段,请重新选择'));
     }
     if ($period->current >= $period->total) {
         return Response::json(array('error_code' => 3, 'message' => '已满人,请重新选择'));
     }
     $schedule = $period->schedule;
     $doctor = $schedule->doctor;
     $user_id = Session::get('user.id');
     // 选择指定挂号账户
     if (Input::has('account_id')) {
         $account_id = Input::get('account_id');
         $account = RegisterAccount::find($account_id);
         if (!isset($account)) {
             return Response::json(array('error_code' => 4, 'message' => '不存在该挂号账户'));
         }
         if ($account->user_id != $user_id) {
             return Response::json(array('error_code' => 5, 'message' => '无效账户'));
         }
     } else {
         $account = RegisterAccount::where('user_id', $user_id)->first();
         if (!isset($account)) {
             return Response::json(array('error_code' => 6, 'message' => '请先申请挂号账户'));
         }
         $account_id = $account->id;
     }
     $user_id = Session::get('user.id');
     $attach = array('period_id' => (int) Input::get('period_id'), 'account_id' => $account_id);
     try {
         $period = Period::find(Input::get('period_id'));
         $schedule = $period->schedule;
         $doctor = $schedule->doctor;
         $order = $this->create_order($user_id, 'APP', json_encode($attach), (int) ($doctor->register_fee * 100));
         $para = array('appid' => $order['appid'], 'partnerid' => WxPayConfig::MCHID, 'prepayid' => $order['prepay_id'], 'package' => 'Sign=WXPay', 'noncestr' => WxPayApi::getNonceStr(), 'timestamp' => time());
         $wxpay_result = new WxPayResults();
         $wxpay_result->FromArray($para);
         $wxpay_result->SetSign();
         $package = $wxpay_result->GetValues();
     } catch (Exception $e) {
         return Response::json(array('error_code' => 1, 'message' => $e->getMessage()));
     }
     return Response::json(array('error_code' => 0, 'package' => $package));
 }
Esempio n. 2
0
 /**
 *
 * 企业支付
 * partner_trade_no、check_name、re_user_name,amount,desc、openid为必填参数
 * appid、mchid、spbill_create_ip、nonce_str不需要填入
     <xml>
     <mch_appid>wxe062425f740c30d8</mch_appid>
     <mchid>10000098</mchid>
     <nonce_str>3PG2J4ILTKCH16CQ2502SI8ZNMTM67VS</nonce_str>
     <partner_trade_no>100000982014120919616</partner_trade_no>
     <openid>ohO4Gt7wVPxIT1A9GjFaMYMiZY1s</openid>
     <check_name>OPTION_CHECK</check_name>
     <re_user_name>张三</re_user_name>
     <amount>100</amount>
     <desc>节日快乐!</desc>
     <spbill_create_ip>10.2.3.10</spbill_create_ip>
     <sign>C97BDBACF37622775366F38B629F45E3</sign>
     </xml>
 
 * @param WxPayRefund $inputObj
 * @param int $timeOut
 * @throws WxPayException
 * @return 成功时返回,其他抛异常
 */
 public static function sendPay($inputObj, $timeOut = 6)
 {
     $url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";
     //检测必填参数
     if (!$inputObj->IsPartner_Trade_No()) {
         //mch_appid
         throw new WxPayException("付款接口中,却少必填partner_trade_no!");
     } elseif (!$inputObj->IsRe_user_name()) {
         throw new WxPayException("付款接口中,却少必填re_user_name!");
     } else {
         if (!$inputObj->IsOpenid()) {
             throw new WxPayException("付款接口中,缺少必填参数openid!");
         } else {
             if (!$inputObj->IsAmount()) {
                 throw new WxPayException("付款接口中,缺少必填参数amount!");
             } else {
                 if (!$inputObj->IsDesc()) {
                     throw new WxPayException("付款接口中,缺少必填参数desc!");
                 }
             }
         }
     }
     $inputObj->SetMch_appid(WxPayConfig::APPID);
     //公众账号ID
     $inputObj->SetMch_id(WxPayConfig::MCHID);
     //商户号
     $inputObj->SetCheck_Name('NO_CHECK');
     //商户号
     $inputObj->SetSpbill_create_ip('127.0.0.1');
     $inputObj->SetNonce_str(self::getNonceStr());
     //随机字符串
     $inputObj->SetSign();
     //签名
     $xml = $inputObj->ToXml();
     // echo htmlspecialchars($xml);
     $startTimeStamp = self::getMillisecond();
     //请求开始时间
     $response = self::postXmlCurl($xml, $url, true, $timeOut);
     $obj = new WxPayResults();
     $obj->FromXml($response);
     $result = $obj->GetValues();
     self::reportCostTime($url, $startTimeStamp, $result);
     //上报请求花费时间
     return $result;
 }