# web.rest.xunhuPay 库模块帮助文档

<details>  <summary>范例</summary>  <p>

注意先导入 web.rest.xunhuPay 库

生成订单：

```aardio
//创建支付客户端
var http = web.rest.xunhuPay();
http.setAuth("APP ID","APP Secret");

//导入支付接口
var hpj = http.api();

//创建订单
var ret,err = hpj.do({
	total_fee = 1;//付款金额
	trade_order_id = "4";//订单 ID，在当前商户需要有唯一性，不要重复
	notify_url = "https://example.com/api/pay/notify/";//付款成功回调页面
	title = "订单标题";
	attach = "备注";
})

//获取付款二维码（图像链接）
var urlQrCode = ret[["url_qrcode"]]
```

查询订单信息：

```aardio
var http = web.rest.xunhuPay();
http.setAuth("APP ID","APP Secret");
var hpj = http.api();

var ret,err = hpj.query({ 
	out_trade_order = "2"; 
})
```
在服务端接收付款通知的页面验证签名是否有效：

```aardio
var http = web.rest.xunhuPay();
http.setAuth("APP ID","APP Secret");
if( !http.verifyRequest() ){
	response.errorStatus(403,"Unauthorized")
	return;
}
```

发起退款：

```aardio
var http = web.rest.xunhuPay();
http.setAuth("APP ID","APP Secret");
var hpj = http.api();

var hpj = http.api();

var ret,err = hpj.refund({ 
    trade_order_id = "商户站内订单号"; 
    reason = "退款理由"
})

if( !ret[["errcode"]]){

	//退款成功
	var succeeded = ret[["refund_status"]]!="UD"

	//退款时间
	var tm = ret[["refund_time"]]
}
else {
	console.log(ret[["errmsg"]],err)
}
```

</p></details>

## web.rest 成员列表 <a id="web.rest" href="#web.rest">&#x23;</a>

### web.rest.xunhuPay <a id="web.rest.xunhuPay" href="#web.rest.xunhuPay">&#x23;</a>
虎皮椒客户端。  
请求参数使用普通表单编码（application/x-www-form-urlencoded ）。  
请求参数中的参数值如果是表，则首先转换为 JSON 。  
如果请求参数值为函数，则每次请求调用该函数取值。  
所有参数值转换为字符串后并用 URLEncode 编码。  

返回数据如果为 JSON 格式或者表单编码则自动解析为对象  

UrlEncoded 解码 时会自动解析 JSON 字段值（必须是对象或数组）  

如果请求编码也是 JSON ，请改用 web.rest.jsonClient

创建 虎皮椒 客户端。  
请求参数使用普通表单编码（application/x-www-form-urlencoded ）。  
请求参数中的参数值如果是表，则首先转换为 JSON 。  
如果请求参数值为函数，则每次请求调用该函数取值。  
所有参数值转换为字符串后并用 URLEncode 编码。  

返回数据如果为 JSON 格式或者表单编码则自动解析为对象  

UrlEncoded 解码 时会自动解析 JSON 字段值（必须是对象或数组）  

如果请求编码也是 JSON ，请改用 web.rest.jsonClient

### web.rest.xunhuPay("UserAgent","代理服务器","绕过代理的主机",连接选项) <a id="web.rest.xunhuPay" href="#web.rest.xunhuPay">&#x23;</a>
创建 REST 客户端，所有参数可选。  
UserAgent 用于自定义 User-Agent 请求标头，用于服务器识别请求程序特征。  
HTTP 代理服务器请指定为 "代理服务器地址:端口" 格式，  

SOCKS 代理服务器请指定为 "socks=代理服务器地址:端口" 格式   
└──  [代理格式说明](https://www.aardio.com/zh-cn/docs/library-guide/std/inet/proxy.html)  

"绕过代理的主机" 用法参考 inet.setProxy 源码的示例，一般不需要指定。  
连接选项可用一个数值参数指定打开会话的选项，一般不需要指定。

### web.rest.xunhuPay() <a id="web.rest.xunhuPay" href="#web.rest.xunhuPay">&#x23;</a>
[返回对象:webRestClientObject](https://www.aardio.com/zh-cn/docs/library-reference/web/rest/client.html#webRestClientObject)
