CmsWeb/App_Code/WxPayApi.cs

(开头部分) 22KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Web;
using System.Net;
using System.IO;
using System.Text;

/// <summary>
///WxPayApi 的摘要说明
/// </summary>
public class WxPayApi
{
    /**
    * 提交被扫支付API
    * 收银员使用扫码设备读取微信用户刷卡授权码以后,二维码或条码信息传送至商户收银台,
    * 由商户收银台或者商户后台调用该接口发起支付。
    * @param WxPayData inputObj 提交给被扫支付API的参数
    * @param int timeOut 超时时间
    * @throws WxPayException
    * @return 成功时返回调用结果,其他抛异常
    */
    public static WxPayData Micropay(WxPayData inputObj, int timeOut = 10)
    {
        string url = "https://api.mch.weixin.qq.com/pay/micropay";
        //检测必填参数
        if (!inputObj.IsSet("body"))
        {
            throw new WxPayException("提交被扫支付API接口中,缺少必填参数body!");
        }
        else if (!inputObj.IsSet("out_trade_no"))
        {
            throw new WxPayException("提交被扫支付API接口中,缺少必填参数out_trade_no!");
        }
        else if (!inputObj.IsSet("total_fee"))
        {
            throw new WxPayException("提交被扫支付API接口中,缺少必填参数total_fee!");
        }
        else if (!inputObj.IsSet("auth_code"))
        {
            throw new WxPayException("提交被扫支付API接口中,缺少必填参数auth_code!");
        }

        inputObj.SetValue("spbill_create_ip", WxPayConfig.IP);//终端ip
        inputObj.SetValue("appid", WxPayConfig.APPID);//公众账号ID
        inputObj.SetValue("mch_id", WxPayConfig.MCHID);//商户号
        inputObj.SetValue("nonce_str", Guid.NewGuid().ToString().Replace("-", ""));//随机字符串
        inputObj.SetValue("sign", inputObj.MakeSign());//签名
        string xml = inputObj.ToXml();

        var start = DateTime.Now;//请求开始时间

        Log.Debug("WxPayApi", "MicroPay request : " + xml);
        string response = HttpService.Post(xml, url, false, timeOut);//调用HTTP通信接口以提交数据到API
        Log.Debug("WxPayApi", "MicroPay response : " + response);

        var end = DateTime.Now;
        int timeCost = (int)((end - start).TotalMilliseconds);//获得接口耗时

        //将xml格式的结果转换为对象以返回
        WxPayData result = new WxPayData();
后面还有 547 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。