food_server/ThinkPHP/Library/Vendor/Wxpay/example/micropay.php
2024-05-30 19:16:59 +08:00

74 lines
2.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>微信支付样例-查退款单</title>
</head>
<?php
/**
*
* example目录下为简单的支付样例仅能用于搭建快速体验微信支付使用
* 样例的作用仅限于指导如何使用sdk在安全上面仅做了简单处理 复制使用样例代码时请慎重
* 请勿直接直接使用样例对外提供服务
*
**/
require_once "../lib/WxPay.Api.php";
require_once "WxPay.MicroPay.php";
require_once 'log.php';
if((isset($_REQUEST["auth_code"]) && !preg_match("/^[0-9]{6,64}$/i", $_REQUEST["auth_code"], $matches)))
{
header('HTTP/1.1 404 Not Found');
exit();
}
//初始化日志
$logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
$log = Log::Init($logHandler, 15);
//打印输出数组信息
function printf_info($data)
{
foreach($data as $key=>$value){
echo "<font color='#00ff55;'>$key</font> : ".htmlspecialchars($value, ENT_QUOTES)." <br/>";
}
}
if(isset($_REQUEST["auth_code"]) && $_REQUEST["auth_code"] != ""){
try {
$auth_code = $_REQUEST["auth_code"];
$input = new WxPayMicroPay();
$input->SetAuth_code($auth_code);
$input->SetBody("刷卡测试样例-支付");
$input->SetTotal_fee("1");
$input->SetOut_trade_no("sdkphp".date("YmdHis"));
$microPay = new MicroPay();
printf_info($microPay->pay($input));
} catch(Exception $e) {
Log::ERROR(json_encode($e));
}
}
/**
* 注意:
* 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 />
<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>
</html>