/** * *退款接口 * */ public static function refund($inputObj, $timeOut = 6, $f1, $f2, $key) { global $_W, $_GPC; $url = "https://api.mch.weixin.qq.com/secapi/pay/refund"; //检测必填参数 if (!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) { throw new WxPayException("退款申请接口中,out_trade_no、transaction_id至少填一个!"); } else { if (!$inputObj->IsOut_refund_noSet()) { throw new WxPayException("退款申请接口中,缺少必填参数out_refund_no!"); } else { if (!$inputObj->IsTotal_feeSet()) { throw new WxPayException("退款申请接口中,缺少必填参数total_fee!"); } else { if (!$inputObj->IsRefund_feeSet()) { throw new WxPayException("退款申请接口中,缺少必填参数refund_fee!"); } else { if (!$inputObj->IsOp_user_idSet()) { throw new WxPayException("退款申请接口中,缺少必填参数op_user_id!"); } } } } } $inputObj->SetNonce_str(self::getNonceStr()); //随机字符串 $inputObj->SetSign($key); //签名 $xml = $inputObj->ToXml(); $startTimeStamp = self::getMillisecond(); //请求开始时间 $response = self::postXmlCurl($xml, $url, true, $timeOut, $f1, $f2); $result = WxPayResults::Init($response); return $result; }
public function verifyNotify() { $xml = file_get_contents('php://input', 'r'); $re = WxPayResults::Init($xml); $this->log->INFO('RESULTS FROM XML:' . json_encode($re)); if ($re['return_code'] == 'FAIL') { $this->log->ERROR($re['return_msg'] . '|' . $re['err_code_des']); throw new Exception("微信 preorder 错误-" . $re['return_msg'], 9001); } return $re; }
/** * * 验证微信签名 */ public static function checkSign() { //获取通知的数据 $xml = $GLOBALS['HTTP_RAW_POST_DATA']; //如果返回成功则验证签名 try { $result = WxPayResults::Init($xml); } catch (WxPayException $e) { return false; } return true; }
public static function orderQuery($inputObj, $timeOut = 6) { $url = "https://api.mch.weixin.qq.com/pay/orderquery"; //检测必填参数 if (!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) { throw new WxPayException("订单查询接口中,out_trade_no、transaction_id至少填一个!"); } $inputObj->SetAppid(WxPayAPPConfig::APPID); //公众账号ID $inputObj->SetMch_id(WxPayAPPConfig::MCHID); //商户号 $inputObj->SetNonce_str(self::getNonceStr()); //随机字符串 $inputObj->SetAppSign(); //签名 $xml = $inputObj->ToXml(); $startTimeStamp = parent::getMillisecond(); //请求开始时间 $response = parent::postXmlCurl($xml, $url, false, $timeOut); $result = WxPayResults::Init($response); parent::reportCostTime($url, $startTimeStamp, $result); //上报请求花费时间 return $result; }
/** * * 支付结果通用通知 * @param function $callback * 直接回调函数使用方法: notify(you_function); * 回调类成员函数方法:notify(array($this, you_function)); * $callback 原型为:function function_name($data){} */ public static function notify($callback, &$msg) { //获取通知的数据 $xml = $GLOBALS['HTTP_RAW_POST_DATA']; //如果返回成功则验证签名 try { $result = WxPayResults::Init($xml); } catch (WxPayException $e) { $msg = $e->errorMessage(); return false; } return call_user_func($callback, $result); }
/** * * 支付结果通用通知 * @param function $callback * 直接回调函数使用方法: notify(you_function); * 回调类成员函数方法:notify(array($this, you_function)); * $callback 原型为:function function_name($data){} */ public static function notify($callback, &$msg) { //获取通知的数据 $xml = file_get_contents("php://input"); //如果返回成功则验证签名 try { $result = WxPayResults::Init($xml); } catch (WxPayException $e) { $msg = $e->errorMessage(); return false; } return call_user_func($callback, $result); }
public function weixin_balance() { App::import('Vendor', 'Weixinpay', array('file' => 'WxPay.Api.php')); $notify = new PayNotifyCallBack(); $res = $notify->Handle(false); $xml = $GLOBALS['HTTP_RAW_POST_DATA']; $result = WxPayResults::Init($xml); $this->loadModel('PaymentApiLog'); $out_trade_no = isset($result["out_trade_no"]) ? $result["out_trade_no"] : ''; $out_trade_no_arr = split("_", $out_trade_no); $api_log_id = $out_trade_no_arr[0]; $payment_api_log = $this->PaymentApiLog->find('first', array('conditions' => array('PaymentApiLog.id' => $api_log_id, 'is_paid' => '0'))); if (!empty($payment_api_log)) { //充值支付 $user_id = $payment_api_log['PaymentApiLog']['type_id']; $add_money = $payment_api_log['PaymentApiLog']['amount']; $user_Info = $this->User->find('first', array('conditions' => array('User.id' => $user_id))); if (!empty($user_Info)) { $user_money = $user_Info['User']['balance']; $user_money = $user_money + $add_money; $user_data['id'] = $user_id; $user_data['balance'] = $user_money; $this->User->save($user_data); $user_Info['User']['balance'] = $user_money; $_SESSION['User'] = $user_Info; $payment_api_log['PaymentApiLog']['is_paid'] = '1'; $this->PaymentApiLog->save($payment_api_log); //添加资金日志 $BalanceLog['UserBalanceLog']['user_id'] = $user_id; $BalanceLog['UserBalanceLog']['amount'] = $payment_api_log['PaymentApiLog']['amount']; $BalanceLog['UserBalanceLog']['admin_user'] = $user_Info['User']['balance']; $BalanceLog['UserBalanceLog']['admin_note'] = ''; $BalanceLog['UserBalanceLog']['system_note'] = '用户余额:' . $user_data['balance'] . '元'; $BalanceLog['UserBalanceLog']['log_type'] = 'B'; $BalanceLog['UserBalanceLog']['type_id'] = $payment_api_log['PaymentApiLog']['id']; $BalanceLog['UserBalanceLog']['created'] = date('Y-m-d H:i:s', time()); $this->UserBalanceLog->save($BalanceLog); } } }
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)); }
function isWeChatIPNValid($ipnXml) { //如果返回成功则验证签名 try { $result = WxPayResults::Init($ipnXml); $this->ipn = $result; } catch (WxPayException $e) { $msg = $e->errorMessage(); return false; } Log::DEBUG("call back ipn:" . json_encode($result)); if (!array_key_exists("transaction_id", $result)) { return false; } if (!$this->Queryorder($result["transaction_id"])) { return false; } return true; }
public function callBack() { $file = '/ding/protected/module/default/cache/callback-' . date("Y-m--d") . '.php'; $xml = $GLOBALS['HTTP_RAW_POST_DATA']; $result = WxPayResults::Init($xml); file_put_contents($file, var_export($result, true), FILE_APPEND); if ($result['result_code'] == 'SUCCESS') { $callBackOrderid = $result['out_trade_no']; $orderStatus = $result['result_code']; $order = DBproxy::getProcedure('Manage')->setDimension(2)->orderUp($orderStatus, 0, $callBackOrderid); if ($order['status'] == 0) { echo 'SUCCESS'; } } }
/** * 发送现金红包 * @param $openid 接收红包用户openid * @param $money 发放金额,单位:分 * @param $total_num 红包个数, 1则为现金红包, 大于等于3则为裂变红包 * @param $send_name 商家名称 * @param $mch_billno 订单号 * @param $act_name 活动名称 * @param $wishing 祝福语 * @param $remark 备注 * @return array * @throws \Exception */ public function sendRedPack($openid, $money, $total_num, $send_name, $mch_billno, $act_name, $wishing, $remark) { $param = new ParamHelper(); $param->setParam("nonce_str", $this->getNonceStr()); $param->setParam("mch_billno", $mch_billno); $param->setParam("mch_id", $this->wx_pay_mchid); $param->setParam("wxappid", $this->appid); $param->setParam("send_name", $send_name); $param->setParam("re_openid", $openid); $param->setParam("total_amount", $money); $param->setParam("total_num", $total_num); $param->setParam("wishing", $wishing); $param->setParam("act_name", $act_name); $param->setParam("remark", $remark); if ($total_num * 100 > $money) { throw new \Exception("每个红包的平均金额必须在1.00元到200.00元之间."); } if ($total_num == 1) { //普通红包 $url = self::SEND_REDPACK_URL; $param->setParam("client_ip", $_SERVER['REMOTE_ADDR']); } else { if ($total_num < 3) { throw new \Exception("裂变红包个数必须介于(包括)3到20之间."); } //裂变红包 $param->setParam("amt_type", "ALL_RAND"); $url = self::SEND_GROUP_REDPACK_URL; } $param->setSign($this->wx_pay_key); $xmlData = $param->toXml(); $response = $this->postXmlCurl($xmlData, $url, true); $result = WxPayResults::init($response, false); return $result; }