/** * 生成支付接口内容 * @param $data * @param bool $debug * @return json */ function jsapipay($data, $debug = false) { // C('weixin.weixin_') //①、获取用户openid $tools = new JsApiPay(); // $openId = $tools->GetOpenid(); if (!empty($data['openid'])) { $openId = $data['openid']; } else { echo "empty openid"; die; } //②、统一下单 $input = new WxPayUnifiedOrder(); $input->SetBody($data['body']); $input->SetAttach($data['attach']); $input->SetOut_trade_no($data['order_sn']); $input->SetTotal_fee($data['total_fee']); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetGoods_tag($data['goods_tag']); $input->SetNotify_url("http://{$_SERVER[HTTP_HOST]}/weixin/notify.html"); $input->SetTrade_type("JSAPI"); $input->SetOpenid($openId); $order = WxPayApi::unifiedOrder($input); if ($debug) { echo '<font color="#f00"><b>统一下单支付单信息</b></font><br/>'; printf_info($order); } $jsApiParameters = $tools->GetJsApiParameters($order); return $jsApiParameters; }
//打印输出数组信息 function printf_info($data) { foreach ($data as $key => $value) { echo "<font color='#00ff55;'>{$key}</font> : {$value} <br/>"; } } if (isset($_REQUEST["auth_code"]) && $_REQUEST["auth_code"] != "") { $auth_code = $_REQUEST["auth_code"]; $input = new WxPayMicroPay(); $input->SetAuth_code($auth_code); $input->SetBody("刷卡测试样例-支付"); $input->SetTotal_fee("1"); $input->SetOut_trade_no(WxPayConfig::MCHID . date("YmdHis")); $microPay = new MicroPay(); printf_info($microPay->pay($input)); } /** * 注意: * 1、提交被扫之后,返回系统繁忙、用户输入密码等错误信息时需要循环查单以确定是否支付成功 * 2、多次(一半10次)确认都未明确成功时需要调用撤单接口撤单,防止用户重复支付 */ ?> <body> <form action="#" method="post"> <div style="margin-left:2%;">商品描述:</div><br/> <input type="text" style="width:96%;height:35px;margin-left:2%;" readonly value="刷卡测试样例-支付" name="auth_code" /><br /><br /> <div style="margin-left:2%;">支付金额:</div><br/> <input type="text" style="width:96%;height:35px;margin-left:2%;" readonly value="1分" name="auth_code" /><br /><br /> <div style="margin-left:2%;">授权码:</div><br/> <input type="text" style="width:96%;height:35px;margin-left:2%;" name="auth_code" /><br /><br />
exit; } //$_REQUEST["out_trade_no"]= "122531270220150304194108"; ///$_REQUEST["total_fee"]= "1"; //$_REQUEST["refund_fee"] = "1"; if (isset($_REQUEST["out_trade_no"]) && $_REQUEST["out_trade_no"] != "") { $out_trade_no = $_REQUEST["out_trade_no"]; $total_fee = $_REQUEST["total_fee"]; $refund_fee = $_REQUEST["refund_fee"]; $input = new WxPayRefund(); $input->SetOut_trade_no($out_trade_no); $input->SetTotal_fee($total_fee); $input->SetRefund_fee($refund_fee); $input->SetOut_refund_no(WxPayConfig::MCHID . date("YmdHis")); $input->SetOp_user_id(WxPayConfig::MCHID); printf_info(WxPayApi::refund($input)); exit; } ?> <body> <form action="#" method="post"> <div style="margin-left:2%;color:#f00">微信订单号和商户订单号选少填一个,微信订单号优先:</div><br/> <div style="margin-left:2%;">微信订单号:</div><br/> <input type="text" style="width:96%;height:35px;margin-left:2%;" name="transaction_id" /><br /><br /> <div style="margin-left:2%;">商户订单号:</div><br/> <input type="text" style="width:96%;height:35px;margin-left:2%;" name="out_trade_no" /><br /><br /> <div style="margin-left:2%;">订单总金额(分):</div><br/> <input type="text" style="width:96%;height:35px;margin-left:2%;" name="total_fee" /><br /><br /> <div style="margin-left:2%;">退款金额(分):</div><br/> <input type="text" style="width:96%;height:35px;margin-left:2%;" name="refund_fee" /><br /><br /> <div align="center">
$openId = $tools->GetOpenid(); //②、统一下单 $input = new WxPayUnifiedOrder(); $input->SetBody("6dygjsapi"); $input->SetAttach("6dygjsapi"); $input->SetOut_trade_no(WxPayConfig::MCHID . date("YmdHis")); $input->SetTotal_fee("1"); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetGoods_tag("6dygjsapi"); $input->SetNotify_url("http://mm.lmcity.cn/weipay/example/notify.php"); $input->SetTrade_type("JSAPI"); $input->SetOpenid($openId); $order = WxPayApi::unifiedOrder($input); echo '<font color="#f00"><b>统一下单支付单信息</b></font><br/>'; 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) */ ?> <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
foreach ($data as $key => $value) { echo "<font color='#f00;'>{$key}</font> : {$value} <br/>"; } } if (isset($_REQUEST["transaction_id"]) && $_REQUEST["transaction_id"] != "") { $transaction_id = $_REQUEST["transaction_id"]; $input = new WxPayOrderQuery(); $input->SetTransaction_id($transaction_id); printf_info(WxPayApi::orderQuery($input)); exit; } if (isset($_REQUEST["out_trade_no"]) && $_REQUEST["out_trade_no"] != "") { $out_trade_no = $_REQUEST["out_trade_no"]; $input = new WxPayOrderQuery(); $input->SetOut_trade_no($out_trade_no); printf_info(WxPayApi::orderQuery($input)); exit; } ?> <body> <form action="#" method="post"> <div style="margin-left:2%;color:#f00">微信订单号和商户订单号选少填一个,微信订单号优先:</div><br/> <div style="margin-left:2%;">微信订单号:</div><br/> <input type="text" style="width:96%;height:35px;margin-left:2%;" name="transaction_id" /><br /><br /> <div style="margin-left:2%;">商户订单号:</div><br/> <input type="text" style="width:96%;height:35px;margin-left:2%;" name="out_trade_no" /><br /><br /> <div align="center"> <input type="submit" value="查询" style="width:210px; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer; color:white; font-size:16px;" type="button" onclick="callpay()" /> </div> </form> </body>
$input->SetOut_trade_no($out_trade_no); printf_info(WxPayApi::refundQuery($input)); exit; } if (isset($_REQUEST["out_refund_no"]) && $_REQUEST["out_refund_no"] != "") { $out_refund_no = $_REQUEST["out_refund_no"]; $input = new WxPayRefundQuery(); $input->SetOut_refund_no($out_refund_no); printf_info(WxPayApi::refundQuery($input)); exit; } if (isset($_REQUEST["refund_id"]) && $_REQUEST["refund_id"] != "") { $refund_id = $_REQUEST["refund_id"]; $input = new WxPayRefundQuery(); $input->SetRefund_id($refund_id); printf_info(WxPayApi::refundQuery($input)); exit; } ?> <body> <form action="#" method="post"> <div style="margin-left:2%;color:#f00">微信订单号、商户订单号、微信订单号、微信退款单号选填至少一个,微信退款单号优先:</div><br/> <div style="margin-left:2%;">微信订单号:</div><br/> <input type="text" style="width:96%;height:35px;margin-left:2%;" name="transaction_id" /><br /><br /> <div style="margin-left:2%;">商户订单号:</div><br/> <input type="text" style="width:96%;height:35px;margin-left:2%;" name="out_trade_no" /><br /><br /> <div style="margin-left:2%;">商户退款单号:</div><br/> <input type="text" style="width:96%;height:35px;margin-left:2%;" name="out_refund_no" /><br /><br /> <div style="margin-left:2%;">微信退款单号:</div><br/> <input type="text" style="width:96%;height:35px;margin-left:2%;" name="refund_id" /><br /><br /> <div align="center">