/** * * 回复通知 * @param bool $needSign 是否需要签名输出 * @throws WxPayException */ private final function ReplyNotify($needSign = true) { //如果需要签名 if ($needSign == true && $this->GetReturn_code() == "SUCCESS") { $this->SetSign(); } $this->wxPayApi->replyNotify($this->ToXml()); }
/** * 组装包含支付信息的url(模式2) */ public function get_payurl() { require_once BASE_PATH . '/api/payment/wxpay/lib/WxPay.Api.php'; require_once BASE_PATH . '/api/payment/wxpay/WxPay.NativePay.php'; require_once BASE_PATH . '/api/payment/wxpay/log.php'; $logHandler = new CLogFileHandler(BASE_DATA_PATH . '/log/wxpay/' . date('Y-m-d') . '.log'); $Logwx = Logwx::Init($logHandler, 15); //统一下单 $input = new WxPayUnifiedOrder(); $input->SetBody($this->_order_info['pay_sn'] . '订单'); // $input->SetBody(C('site_name').'订单'); $input->SetAttach($this->_order_info['order_type'] == 'vr_order' ? 'v' : 'r'); $input->SetOut_trade_no($this->_order_info['pay_sn']); $input->SetTotal_fee($this->_order_info['api_pay_amount'] * 100); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 3600)); $input->SetGoods_tag(''); $input->SetNotify_url(SHOP_SITE_URL . '/api/payment/wxpay/notify_url.php'); $input->SetTrade_type("NATIVE"); //$input->SetOpenid($openId); $input->SetProduct_id($this->_order_info['pay_sn']); $result = WxPayApi::unifiedOrder($input); // header("Content-type:text/html;charset=utf-8"); // print_R($result);exit; Logwx::DEBUG("unifiedorder-:" . json_encode($result)); return $result["code_url"]; }
public function GetOrderInfo($input) { if ($input->GetTrade_type() == "APP") { $result = WxPayApi::unifiedOrder($input, true); return $result; } }
public function Queryorder($transaction_id) { $input = new WxPayOrderQuery(); $input->SetTransaction_id($transaction_id); $result = WxPayApi::orderQuery($input); \Log::info("query:" . json_encode($result)); if (array_key_exists("return_code", $result) && array_key_exists("result_code", $result) && $result["return_code"] == "SUCCESS" && $result["result_code"] == "SUCCESS") { // 处理订单 $pay = \App\Pay::find($result['out_trade_no']); $pay->pay($result['transaction_id']); if ($pay->state < 2) { $pay->state = '2'; $pay->bak_id = '0'; $pay->other_id = $result['transaction_id']; $pay->save(); } else { if ($pay->state == 2) { $pay->bak_id++; $pay->save(); } } return true; } return false; }
/** * jsapi支付 * @param string $user_id 用户id * @param int $order_id * @param string $order_sn 订单号 * @param int $total_fee 费用 * @param string $body 商品或支付单简要描述 * @param string $goods_tag 商品标记 * @param string $attach 自定义数据 * @return array */ public function JsApiPay($user_id, $order_id, $order_sn, $total_fee, $body = '', $goods_tag = '', $attach = '') { if (empty($user_id) || empty($total_fee)) { return ['status' => -1, 'message' => '数据错误']; } $tools = new JsApiPay(); $openId = UserModel::instance()->getOpenId($user_id); if (empty($openId)) { $openId = $tools->GetOpenid(); // return ['status'=> -2 , 'message'=>'user_id错误']; } $input = new \WxPayUnifiedOrder(); $input->SetBody($body); $input->SetAttach($attach); $input->SetOut_trade_no($order_sn); //\WxPayConfig::MCHID.date("YmdHis") $input->SetTotal_fee($total_fee); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetGoods_tag($goods_tag); $input->SetTrade_type("JSAPI"); $input->SetOpenid($openId); $order = \WxPayApi::unifiedOrder($input); if ($order['return_code'] != 'SUCCESS') { return ['status' => -10, 'message' => $order['return_msg']]; } $jsApiParameters = $tools->GetJsApiParameters($order); $this->addPayLog($openId, $order_id, $input); return ['status' => 1, 'message' => $jsApiParameters]; }
public function getAppPaymentParameters($order) { /* $order =null; $order = $this->queryOrder($out_trade_no); // print json_encode($order) .PHP_EOL; if ($order) { $input = new \WxPayReverse(); $input->SetOut_trade_no($out_trade_no); $result = \WxPayApi::reverse($input); print('reserve:'.json_encode($result)) .PHP_EOL; // $input = new \WxPayCloseOrder(); // $input->SetOut_trade_no($out_trade_no); // $result = \WxPayApi::closeOrder($input); // print('close:'.json_encode($result)) .PHP_EOL; } */ $wxPayConfig = $this->wxPayApi->getWxPayConfig(); // print( json_encode($order ) ) .PHP_EOL; $prepay_id = $order['prepay_id']; $response = array('appid' => $wxPayConfig['APPID'], 'partnerid' => $wxPayConfig['MCHID'], 'prepayid' => $prepay_id, 'package' => 'Sign=WXPay', 'noncestr' => \WxPayApi::getNonceStr(), 'timestamp' => time()); $response['sign'] = $this->calculateSign($response, $wxPayConfig['KEY']); // send it to APP return $response; }
/** * * 生成直接支付url,支付url有效期为2小时,模式二 * @param UnifiedOrderInput $input */ public function GetPayUrl($input) { if ($input->GetTrade_type() == "NATIVE") { $result = WxPayApi::unifiedOrder($input); return $result; } }
public function Queryorder($transaction_id) { $input = new WxPayOrderQuery(); $input->SetTransaction_id($transaction_id); $result = WxPayApi::orderQuery($input); // Log::DEBUG("query:" . json_encode($result)); ilog(iLOG_INFO, 'Queryorder:' . json_encode($result), __LINE__); if (array_key_exists("return_code", $result) && array_key_exists("result_code", $result) && $result["return_code"] == "SUCCESS" && $result["result_code"] == "SUCCESS") { $user_trade_no = $result['out_trade_no']; $transaction_id = $result['transaction_id']; $info1 = 'wxapp/interface/appnotify.php,operator success,session == trade_no,ordernum:' . $user_trade_no . ',wxno:' . $transaction_id; ilog(iLOG_INFO, $info1, __LINE__); $body_arr['order_no'] = $user_trade_no; $body_arr['pay_result'] = 2; //支付成功 $body_arr['alipay_no'] = $transaction_id; //微信流水号 $body_arr['channel'] = 'wxapp'; // $ret = exec_procedure($body_arr, 'p_order_pay_result'); if ($ret['status'] == 0 || $ret['status'] == 1040) { //成功,返回success return true; } else { //返回错误码,非success $info = 'wxapp/interface/appnotify.php,p_order_pay_result failed'; ilog(iLOG_INFO, $info, __LINE__); return false; } } $info = 'wxapp/interface/appnotify.php,operator failed'; ilog(iLOG_INFO, $info, __LINE__); //验证失败 return false; }
/** 二维码订单 */ public function generateQrOrder() { $input = $this->unifiedOrder(); $input->SetTrade_type("NATIVE"); $input->SetProduct_id("123456789"); $order = \WxPayApi::unifiedOrder($input); $qrUrl = $order["code_url"]; return $qrUrl; }
public function myrefund($transid) { global $_W, $_GPC; include_once 'WxPay.Api.php'; $WxPayApi = new WxPayApi(); $input = new WxPayRefund(); load()->func('communication'); load()->model('account'); $accounts = uni_accounts(); $acid = $_W['uniacid']; $path_cert = '../addons/feng_fightgroups/cert/' . $_W['uniacid'] . '/apiclient_cert.pem'; //证书路径 $path_key = '../addons/feng_fightgroups/cert/' . $_W['uniacid'] . '/apiclient_key.pem'; //证书路径 $key = $this->module['config']['apikey']; //商户支付秘钥(API秘钥) $appid = $accounts[$acid]['key']; //身份标识(appid) // $appsecret = $accounts[$acid]['secret'];//身份密钥(appsecret) $mchid = $this->module['config']['mchid']; //微信支付商户号(mchid) $order_out = pdo_fetch("select * from" . tablename('tg_order') . "where transid = '{$transid}'"); $fee = $order_out['price'] * 100; //退款金额 $refundid = $transid; //微信订单号 message("key=" . $key . "appid=" . $appid . "mchid=" . $mchid . "fee=" . $fee . "refundid=" . $refundid); exit; /*$input:退款必须要的参数*/ $input->SetAppid($appid); $input->SetMch_id($mchid); $input->SetOp_user_id($mchid); $input->SetOut_refund_no($mchid . date("YmdHis")); $input->SetRefund_fee($fee); $input->SetTotal_fee($fee); $input->SetTransaction_id($refundid); $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key); if ($result['return_code'] == 'SUCCESS') { return 'success'; } else { return 'fail'; } }
public function Queryorder($transaction_id) { $input = new WxPayOrderQuery(); $input->SetTransaction_id($transaction_id); $result = WxPayApi::orderQuery($input); if (array_key_exists("return_code", $result) && array_key_exists("result_code", $result) && $result["return_code"] == "SUCCESS" && $result["result_code"] == "SUCCESS") { return true; } return false; }
public function wxJsPay() { $list = isset($_SESSION['orderinfo']) ? $_SESSION['orderinfo'] : array(); if (!isset($_SESSION['orderinfo'])) { header("Location:" . appurl('getMeOrder')); die; } //验证是否能预定 if (isset($_SESSION['orderList'])) { foreach ($_SESSION['orderList'] as $key => $value) { $this->checkCanSum($value['bookid'], $value); if (!$this->checkBook($value['bookid'])) { $this->alert($value['title'] . '已经售卖结束'); exit; } } } //初始化日志 $logHandler = new CLogFileHandler("../logs/" . date('Y-m-d') . '.log'); $log = Log::Init($logHandler, 15); //①、获取用户openid $tools = new JsApiPay(); $openId = $tools->GetOpenid(); //②、统一下单 //价钱转成分 $totalFee = $list['allPrice'] * 100; $input = new WxPayUnifiedOrder(); $input->SetBody("订单"); $input->SetAttach("订单"); $input->SetOut_trade_no($list['orderid']); $input->SetTotal_fee($totalFee); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetGoods_tag("订单"); $input->SetNotify_url(appurl('callBack')); // "http://paysdk.weixin.qq.com/example/notify.php" $input->SetTrade_type("JSAPI"); $input->SetOpenid($openId); $order = WxPayApi::unifiedOrder($input); echo '<font color="#f00"><b>支付中,客官请稍后....</b></font><br/>'; // $this->printf_info($order); $jsApiParameters = $tools->GetJsApiParameters($order); //获取共享收货地址js函数参数 $editAddress = $tools->GetEditAddressParameters(); //③、在支持成功回调通知中处理成功之后的事宜,见 notify.php /** * 注意: * 1、当你的回调地址不可访问的时候,回调通知会失败,可以通过查询订单来确认支付是否成功 * 2、jsapi支付时需要填入用户openid,WxPay.JsApiPay.php中有获取openid流程 (文档可以参考微信公众平台“网页授权接口”, * 参考http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html) */ $data = array('jsApiParameters' => $jsApiParameters, 'editAddress' => $editAddress, 'orderid' => $list['orderid'], 'pageTitle' => '支付'); unset($_SESSION['orderinfo']); $this->layoutRender('/wxpay', $data); }
public function Queryorder($transaction_id) { $input = new WxPayOrderQuery(); $input->SetTransaction_id($transaction_id); $result = WxPayApi::orderQuery($input); if (array_key_exists("return_code", $result) && array_key_exists("result_code", $result) && $result["return_code"] == "SUCCESS" && $result["result_code"] == "SUCCESS") { return true; } $log = Log::factory(NT_LOGS_PATH . 'wxpay_saoma/'); $log->write('wxpay_saoma_notify_orderQuery', "订单查询失败\n" . json_encode($result) . "\n"); return false; }
public function Queryorder($mpid, $transaction_id) { //\TMS_APP::M('log')->log('debug', 'pay-Queryorder', '0'); $input = new \WxPayOrderQuery(); $input->SetTransaction_id($transaction_id); $result = \WxPayApi::orderQuery($mpid, $input); if (array_key_exists("return_code", $result) && array_key_exists("result_code", $result) && $result["return_code"] == "SUCCESS" && $result["result_code"] == "SUCCESS") { return true; } //\TMS_APP::M('log')->log('debug', 'pay-Queryorder', 'ok'); return false; }
/** 二维码订单 */ public function generateQrOrder($scheme) { $user = Yii::$app->session->get('user'); $input = $this->unifiedOrder($scheme['payMoney']); $input->SetTrade_type("NATIVE"); $input->SetProduct_id("123456789"); $input->SetAttach($user['userId'] . "|" . $scheme['getBitcoin']); //传递用户id和获取到的云豆数 $order = \WxPayApi::unifiedOrder($input); $qrUrl = $order["code_url"]; return $qrUrl; }
public function Queryorder($data) { $input = new WxPayOrderQuery(); $input->SetTransaction_id($data['transaction_id']); $input->SetTradeType($data['trade_type']); $result = WxPayApi::orderQuery($input, Config::API_TIMEOUT); $this->query_data = $result; Log::DEBUG("query:" . json_encode($result)); if (array_key_exists("return_code", $result) && array_key_exists("result_code", $result) && $result["return_code"] == "SUCCESS" && $result["result_code"] == "SUCCESS") { return true; } return false; }
private function queryOrder($out_trade_no, $inStatus = '') { if (isset($out_trade_no) && $out_trade_no != "") { $input = new WxPayOrderQuery(); $input->SetOut_trade_no($out_trade_no); $info = WxPayApi::orderQuery($input); if ($inStatus == 'code') { return $info['trade_state']; } $status = orderState($info['trade_state']); } return $status; }
public function Queryorder($transaction_id) { $input = new WxPayOrderQuery(); $input->SetTransaction_id($transaction_id); $result = WxPayApi::orderQuery($input); Log::DEBUG("query:" . json_encode($result)); if (array_key_exists("return_code", $result) && array_key_exists("result_code", $result) && $result["return_code"] == "SUCCESS" && $result["result_code"] == "SUCCESS") { return true; // echo "OK"; } return false; // echo "Fail"; }
public function queryOrder($transaction_id) { $input = new WxPayOrderQuery(); $input->SetTransaction_id($transaction_id); $result = WxPayApi::orderQuery($input); Log::DEBUG("query:" . Tools::jsonEncode($result)); if (array_key_exists("return_code", $result) && array_key_exists("result_code", $result) && $result["return_code"] == "SUCCESS" && $result["result_code"] == "SUCCESS") { if (!$this->changeOrderStatus($result['out_trade_no'])) { Log::DEBUG("change:5.更改定单状态失败"); } return true; } return false; }
public function Queryorder($transaction_id) { $input = new WxPayOrderQuery(); $input->SetTransaction_id($transaction_id); $result = WxPayApi::orderQuery($input); Log::DEBUG("query:" . json_encode($result)); if (array_key_exists("return_code", $result) && array_key_exists("result_code", $result) && $result["return_code"] == "SUCCESS" && $result["result_code"] == "SUCCESS") { //支付成功后 开通相关的操作方法 require_once dirname(__FILE__) . '/../common.inc.php'; $url = $_CFG['site_domain'] . $_CFG['site_dir'] . "include/payment/respond_weixinpay.php"; $return_oid = $this->curl_file_get_contents($url, $result); @unlink(QISHI_ROOT_PATH . 'data/wxpay/' . $return_oid . '.tmp'); return true; } return false; }
function getPrepayId($total_amount, $order_number, $attach) { $input = new WxPayUnifiedOrder(); $input->SetBody("美果优鲜订单"); $input->SetAttach("缤纷水果"); $input->SetOut_trade_no($attach); $input->SetTotal_fee($total_amount * 100); $input->SetAttach($order_number); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetGoods_tag("商品标签"); $input->SetNotify_url("https://dev1.meiguoyouxian.com/magento/custom/api/util/wx.php"); $input->SetTrade_type("APP"); $order = WxPayApi::unifiedOrder($input); return $order; }
/** * * 获取jsapi支付的参数 * @param array $UnifiedOrderResult 统一支付接口返回的数据 * @throws WxPayException * * @return json数据,可直接填入js函数作为参数 */ public function GetJsApiParameters($UnifiedOrderResult) { if (!array_key_exists("appid", $UnifiedOrderResult) || !array_key_exists("prepay_id", $UnifiedOrderResult) || $UnifiedOrderResult['prepay_id'] == "") { throw new WxPayException("参数错误"); } $jsapi = new WxPayJsApiPay(); $jsapi->SetAppid($UnifiedOrderResult["appid"]); $timeStamp = time(); $jsapi->SetTimeStamp("{$timeStamp}"); $jsapi->SetNonceStr(WxPayApi::getNonceStr()); $jsapi->SetPackage("prepay_id=" . $UnifiedOrderResult['prepay_id']); $jsapi->SetSignType("MD5"); $jsapi->SetPaySign($jsapi->MakeSign()); $parameters = json_encode($jsapi->GetValues()); return $parameters; }
public function queryOrder($out_trade_no) { $input = new \WxPayOrderQuery(); $input->setWxPayApi($this->wxPayApi); $input->SetOut_trade_no($out_trade_no); $result = \WxPayApi::orderQuery($input); /* if(array_key_exists("return_code", $result) && array_key_exists("result_code", $result) && $result["return_code"] == "SUCCESS" && $result["result_code"] == "SUCCESS") { return true; } */ return $result; }
/** * * 回调入口 * @param bool $needSign 是否需要签名输出 */ public final function Handle($needSign = true) { $msg = "OK"; //当返回false的时候,表示notify中调用NotifyCallBack回调失败获取签名校验失败,此时直接回复失败 $result = WxPayApi::notify(array($this, 'NotifyCallBack'), $msg); if ($result == false) { $this->SetReturn_code("FAIL"); $this->SetReturn_msg($msg); $this->ReplyNotify(false); return; } else { //该分支在成功回调到NotifyCallBack方法,处理完成之后流程 $this->SetReturn_code("SUCCESS"); $this->SetReturn_msg("OK"); } $this->ReplyNotify($needSign); }
public function preOrder($param) { $order = new WxPayUnifiedOrder(); $order->SetOut_trade_no($param['out_trade_no']); $order->SetTotal_fee($param['total_fee'] * 100); $order->SetTrade_type('APP'); $order->SetBody($param['body']); $order->SetDetail($param['detail']); $order->SetNotify_url($this->_notify_url); $re = WxPayApi::unifiedOrder($order); if ($re['result_code'] == 'FAIL') { throw new Exception("微信 preorder 错误-" . $re['err_code_des'], 9001); } if ($re['return_code'] == 'FAIL') { throw new Exception("微信 preorder 错误-" . $re['return_msg'], 9001); } return $re; }
/** * * 获取jsapi支付的参数 * @param array $UnifiedOrderResult 统一支付接口返回的数据 * @throws WxPayException * * @return json数据,可直接填入js函数作为参数 */ public function GetJsApiParameters($UnifiedOrderResult) { if (!array_key_exists("appid", $UnifiedOrderResult) || !array_key_exists("prepay_id", $UnifiedOrderResult) || $UnifiedOrderResult['prepay_id'] == "") { // throw new WxPayException("参数错误"); Yii::log('WxJsPayHelper 71line', CLogger::LEVEL_ERROR, 'WxJsPayHelper'); Yii::app()->request->redirect(Assist::getDefaultURL()); } $jsapi = new WxPayJsApiPay(); $jsapi->SetAppid($UnifiedOrderResult["appid"]); $timeStamp = time(); $jsapi->SetTimeStamp($timeStamp); $jsapi->SetNonceStr(WxPayApi::getNonceStr()); $jsapi->SetPackage("prepay_id=" . $UnifiedOrderResult['prepay_id']); $jsapi->SetSignType("MD5"); $jsapi->SetPaySign($jsapi->MakeSign()); $parameters = json_encode($jsapi->GetValues()); return $parameters; }
public function Queryorder($transaction_id) { $input = new WxPayOrderQuery(); $input->SetTransaction_id($transaction_id); $result = WxPayApi::orderQuery($input); Log::DEBUG("query:" . json_encode($result)); if (array_key_exists("return_code", $result) && array_key_exists("result_code", $result) && $result["return_code"] == "SUCCESS" && $result["result_code"] == "SUCCESS") { $url = "http://" . $_SERVER['SERVER_NAME'] . "/index.php?g=weixin&m=scan&a=notify"; $post_params = $result; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params); $output = curl_exec($ch); curl_close($ch); return true; } return false; }
public function NotifyProcess($data) { if (!array_key_exists("openid", $data) || !array_key_exists("product_id", $data)) { $this->msg = "回调数据异常"; return false; } $openid = $data["openid"]; $product_id = $data["product_id"]; //统一下单 $result = $this->unifiedorder($openid, $product_id, $data); if (!array_key_exists("appid", $result) || !array_key_exists("mch_id", $result) || !array_key_exists("prepay_id", $result)) { $this->msg = "统一下单失败"; return false; } $this->SetData("appid", $result["appid"]); $this->SetData("mch_id", $result["mch_id"]); $this->SetData("nonce_str", WxPayApi::getNonceStr()); $this->SetData("prepay_id", $result["prepay_id"]); $this->SetData("result_code", "SUCCESS"); $this->SetData("err_code_des", "OK"); return true; }
/** * 统一下单 * * @param $amount * * @return string */ private function getUnifiedOrder($amount) { $tools = new \JsApiPay(); $openId = $tools->GetOpenid(); //获取用户openID $outTradeNo = \tools\Tools::uuid(); $input = new \WxPayUnifiedOrder(); $input->SetBody($this->data['memo']); $input->SetAttach($this->data['id']); $input->SetOut_trade_no($outTradeNo); $input->SetTotal_fee($this->amount); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetGoods_tag($this->data['memo']); $input->SetNotify_url($this->notify_url); $input->SetTrade_type("JSAPI"); $input->SetOpenid($openId); $order = \WxPayApi::unifiedOrder($input); $jsApiParameters = $tools->GetJsApiParameters($order); //获取共享收货地址js函数参数 $editAddress = $tools->GetEditAddressParameters(); return ['jsApiParameters' => $jsApiParameters, 'editAddress' => $editAddress, 'amount' => $amount, 'orderId' => $this->data['id']]; }
public function pay_get() { $order = I('get.order', ''); $m = M('orders'); // $map['from_member_id'] = $this->uid; $map['order_number'] = $order; // $map['status'] = 0; $info = $m->where($map)->find(); if (empty($info)) { //未支付订单不存在 $this->error(5015); } $total = $info['total'] * 100; $describe = 'testname'; require_once APP_PATH . "SDK/Payment/wechat/lib/WxPay.Api.php"; $input = new \WxPayUnifiedOrder(); //设置公众账号ID $input->SetAppid(\WxPayConfig::APPID); //设置商户号 $input->SetMch_id(\WxPayConfig::MCHID); //设置随机字符串 $input->SetNonce_str(\WxPayApi::getNonceStr()); //设置商品描述 $input->SetBody($describe); //设置商户订单号 $input->SetOut_trade_no($info['order_number']); //设置总金额 $input->SetTotal_fee($total); //设置终端IP $input->SetSpbill_create_ip(get_client_ip()); //设置通知地址 $input->SetNotify_url(U('Wxpay/callback@api')); //设置交易类型 $input->SetTrade_type('APP'); $order = \WxPayApi::unifiedOrder($input); $this->success($order); }