public function getResponse() { /*{{{*/ try { $request = new Request(); $postInfo = $request->getAllSafePost(); $response = new quickpay_service($postInfo, quickpay_conf::RESPONSE); if ($response->get('respCode') != quickpay_service::RESP_SUCCESS) { $this->data = false; return false; } //获取数据(若以后做退款,需要保存一些信息) $this->data = $response->get_args(); } catch (Exception $ex) { file_put_contents('/tmp/exception_unionpay.txt', var_export($ex, true)); } }
public function notify($request) { unset($request['city']); unset($request['ctl']); unset($request['act']); unset($request['class_name']); unset($_POST['city']); unset($_POST['ctl']); unset($_POST['act']); unset($_POST['class_name']); $upop_evn = $this->upop_evn; $return_res = array('info' => '', 'status' => false); $payment = $GLOBALS['db']->getRow("select id,config from " . DB_PREFIX . "payment where class_name='Upop'"); $payment['config'] = unserialize($payment['config']); // 商户名称 quickpay_conf::$pay_params['merAbbr'] = $payment['config']['upop_merAbbr']; foreach (Upop_payment::$api_url[$upop_evn] as $key => $value) { quickpay_conf::${$key} = $value; } if ($upop_evn == '2') { quickpay_conf::$security_key = $payment['config']['upop_security_key']; quickpay_conf::$pay_params['merId'] = $payment['config']['upop_account']; } else { if ($upop_evn == '1') { quickpay_conf::$security_key = $payment['config']['upop_security_key_pm']; quickpay_conf::$pay_params['merId'] = $payment['config']['upop_account_pm']; } else { if ($upop_evn == '0') { quickpay_conf::$security_key = $payment['upop_security_key']; quickpay_conf::$pay_params['merId'] = $payment['upop_account']; } } } try { $response = new quickpay_service($request, quickpay_conf::RESPONSE); if ($response->get('respCode') != quickpay_service::RESP_SUCCESS) { $err = sprintf("Error: %d => %s", $response->get('respCode'), $response->get('respMsg')); showErr($err); } $arr_ret = $response->get_args(); if (quickpay_conf::$pay_params['merId'] != $arr_ret['merId']) { echo "fail"; die; } // 如果未支付成功。 if ($arr_ret['respCode'] != '00') { echo "fail"; die; } //告诉用户交易完成 $payment_notice_sn = $arr_ret['orderNumber']; $outer_notice_sn = $arr_ret['orderNumber']; $payment_notice = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "payment_notice where notice_sn = '" . $payment_notice_sn . "'"); $order_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order where id = " . $payment_notice['order_id']); require_once APP_ROOT_PATH . "system/model/cart.php"; $rs = payment_paid($payment_notice['id']); if ($rs) { $rs = order_paid($payment_notice['order_id']); if ($rs) { //开始更新相应的outer_notice_sn $GLOBALS['db']->query("update " . DB_PREFIX . "payment_notice set outer_notice_sn = '" . $outer_notice_sn . "' where id = " . $payment_notice['id']); echo "Success"; } else { echo "Success"; } } else { app_redirect(url("index", "payment#pay", array("id" => $payment_notice['id']))); } } catch (Exception $exp) { $str .= var_export($exp, true); echo "fail"; } }
<?php require_once '../quickpay_service.php'; try { $response = new quickpay_service($_POST, quickpay_conf::RESPONSE); if ($response->get('respCode') != quickpay_service::RESP_SUCCESS) { $err = sprintf("Error: %d => %s", $response->get('respCode'), $response->get('respMsg')); throw new Exception($err); } $arr_ret = $response->get_args(); //更新数据库,将交易状态设置为已付款 //注意保存qid,以便调用后台接口进行退货/消费撤销 //以下仅用于测试 file_put_contents('notify.txt', var_export($arr_ret, true)); } catch (Exception $exp) { //后台通知出错 file_put_contents('notify.txt', var_export($exp, true)); }
$param['orderAmount'] = 110; //交易金额 $param['orderNumber'] = date('YmdHis') . strval(mt_rand(100, 999)); //订单号,必须唯一(不能与原交易相同) $param['orderTime'] = date('YmdHis'); //交易时间, YYYYmmhhddHHMMSS $param['orderCurrency'] = quickpay_conf::CURRENCY_CNY; //交易币种, $param['customerIp'] = $_SERVER['REMOTE_ADDR']; //用户IP $param['frontEndUrl'] = ""; //前台回调URL, 后台交易可为空 $param['backEndUrl'] = "http://www.unionpay.com/exa/back_notify.php"; //后台回调URL //其余可填空的参数可以不填写 //提交 $pay_service = new quickpay_service($param, quickpay_conf::BACK_PAY); $ret = $pay_service->post(); //同步返回(表示服务器已收到后台接口请求), 处理成功与否以后台通知为准;或使用主动查询 $response = new quickpay_service($ret, quickpay_conf::RESPONSE); var_dump($response); if ($response->get('respCode') != quickpay_service::RESP_SUCCESS) { //错误处理 $err = sprintf("Error: %d => %s", $response->get('respCode'), $response->get('respMsg')); throw new Exception($err); } //后续处理 $arr_ret = $response->get_args(); var_dump($arr_ret); echo "后台交易返回:\n" . var_export($arr_ret, true); //此行仅用于测试输出
$transType = quickpay_conf::CONSUME; $orderNumber = "20130329163920172"; $orderTime = "20130329163920172"; // */ //需要填入的部分 $param['transType'] = $transType; //交易类型 $param['orderNumber'] = $orderNumber; //订单号 $param['orderTime'] = $orderTime; //订单时间 //提交查询 $query = new quickpay_service($param, quickpay_conf::QUERY); $ret = $query->post(); //返回查询结果 $response = new quickpay_service($ret, quickpay_conf::RESPONSE); //后续处理 $arr_ret = $response->get_args(); echo "查询请求返回:<pre>\n" . var_export($arr_ret, true) . "</pre>"; $respCode = $response->get('respCode'); $queryResult = $response->get('queryResult'); if ($queryResult == quickpay_service::QUERY_FAIL) { echo "交易失败[respCode:{$respCode}]!\n"; //更新数据库, 设置为交易失败 } else { if ($queryResult == quickpay_service::QUERY_INVALID) { //出错 echo "不存在此交易!\n"; } else { if ($respCode == quickpay_service::RESP_SUCCESS && $queryResult == quickpay_service::QUERY_SUCCESS) { echo "交易成功!\n";
quickpay_conf::$pay_params['merAbbr'] = $cfg_yinlian_mername; //商户名称 $param['transType'] = quickpay_conf::CONSUME; //交易类型,CONSUME or PRE_AUTH $param['orderAmount'] = $orderAmount; //交易金额 $param['orderNumber'] = $orderNumber; //订单号,必须唯一 $param['orderTime'] = date('YmdHis'); //交易时间, YYYYmmhhddHHMMSS $param['orderCurrency'] = quickpay_conf::CURRENCY_CNY; //交易币种,CURRENCY_CNY=>人民币 $param['customerIp'] = $_SERVER['REMOTE_ADDR']; //用户IP $param['frontEndUrl'] = $GLOBALS['cfg_basehost'] . "/yinlian/front_notify.php"; //前台回调URL $param['backEndUrl'] = $GLOBALS['cfg_basehost'] . "/yinlian/back_notify.php"; //后台回调URL /* 可填空字段 $param['commodityUrl'] = "http://www.example.com/product?name=商品"; //商品URL $param['commodityName'] = '商品名称'; //商品名称 $param['commodityUnitPrice'] = 11000; //商品单价 $param['commodityQuantity'] = 1; //商品数量 //*/ //其余可填空的参数可以不填写 $pay_service = new quickpay_service($param, quickpay_conf::FRONT_PAY); $html = $pay_service->create_html(); header("Content-Type: text/html; charset=" . quickpay_conf::$pay_params['charset']); //print_r($pay_service); echo $html; //自动post表单