恢复绿色ui前做备份
This commit is contained in:
@@ -212,8 +212,6 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="province.cs" />
|
||||
<Compile Include="QueryString.cs" />
|
||||
<Compile Include="SalesRewardCalculator.cs" />
|
||||
<Compile Include="SalesRewardDemo.cs" />
|
||||
<Compile Include="Security.cs" />
|
||||
<Compile Include="SqlDbHelper_U.cs" />
|
||||
<Compile Include="Tools.cs" />
|
||||
@@ -230,6 +228,7 @@
|
||||
<Compile Include="WXPay.JsonUtils.cs" />
|
||||
<Compile Include="WXPay.Log.cs" />
|
||||
<Compile Include="WXPay.MicroPay.cs" />
|
||||
<Compile Include="WXPay.MiniProgramPay.cs" />
|
||||
<Compile Include="WXPay.NativeNotify.cs" />
|
||||
<Compile Include="WXPay.NativePay.cs" />
|
||||
<Compile Include="WXPay.Notify.cs" />
|
||||
|
||||
726
Mtxfw.Utility/WXPay.MiniProgramPay.cs
Normal file
726
Mtxfw.Utility/WXPay.MiniProgramPay.cs
Normal file
@@ -0,0 +1,726 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using LitJson;
|
||||
|
||||
namespace Mtxfw.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// 微信小程序支付结果类
|
||||
/// 用于封装创建JSAPI支付订单后的返回结果
|
||||
/// </summary>
|
||||
public class MiniProgramPayResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 支付订单创建是否成功
|
||||
/// true: 成功 false: 失败
|
||||
/// </summary>
|
||||
public bool Success { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 结果消息描述
|
||||
/// 成功时为"下单成功",失败时为具体错误信息
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 时间戳
|
||||
/// 自1970年1月1日以来的秒数,用于小程序端调起支付
|
||||
/// </summary>
|
||||
public string TimeStamp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 随机字符串
|
||||
/// 32位以内的随机串,用于签名计算
|
||||
/// </summary>
|
||||
public string NonceStr { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 订单详情扩展字符串
|
||||
/// 格式: prepay_id=xxx,小程序端调起支付时需要此参数
|
||||
/// </summary>
|
||||
public string Package { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 签名
|
||||
/// 用于小程序端调起支付时的安全校验
|
||||
/// </summary>
|
||||
public string PaySign { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 签名类型
|
||||
/// 固定值: MD5
|
||||
/// </summary>
|
||||
public string SignType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 预支付交易会话标识
|
||||
/// 微信返回的预支付ID,有效期2小时
|
||||
/// </summary>
|
||||
public string PrepayId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 商户订单号
|
||||
/// 商户系统内部的订单号,要求32个字符内,唯一性
|
||||
/// </summary>
|
||||
public string OutTradeNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 微信支付订单号
|
||||
/// 微信支付系统生成的订单号,查询订单时使用
|
||||
/// </summary>
|
||||
public string TransactionId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 错误码
|
||||
/// 支付失败时的错误代码,如: NOTENOUGH(余额不足)
|
||||
/// </summary>
|
||||
public string ErrCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 错误码描述
|
||||
/// 支付失败时的错误详细信息
|
||||
/// </summary>
|
||||
public string ErrCodeDes { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 微信小程序支付回调通知结果类
|
||||
/// 用于封装处理支付回调通知后的返回结果
|
||||
/// </summary>
|
||||
public class MiniProgramPayNotifyResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 支付回调处理是否成功
|
||||
/// true: 成功 false: 失败
|
||||
/// </summary>
|
||||
public bool Success { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 结果消息描述
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 商户订单号
|
||||
/// 商户系统内部的订单号
|
||||
/// </summary>
|
||||
public string OutTradeNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 微信支付订单号
|
||||
/// 微信支付系统生成的订单号
|
||||
/// </summary>
|
||||
public string TransactionId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 订单总金额
|
||||
/// 单位: 分,需要转换为元显示
|
||||
/// </summary>
|
||||
public int TotalFee { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户标识
|
||||
/// 用户在商户appid下的唯一标识
|
||||
/// </summary>
|
||||
public string OpenId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 支付完成时间
|
||||
/// 格式: yyyyMMddHHmmss
|
||||
/// </summary>
|
||||
public string TimeEnd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 银行类型
|
||||
/// 银行编码,如: CMC(招商银行)
|
||||
/// </summary>
|
||||
public string BankType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回给微信的XML响应
|
||||
/// 用于告知微信支付后台处理结果
|
||||
/// </summary>
|
||||
public string ResultXml { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 微信小程序支付核心类
|
||||
/// 提供创建JSAPI支付订单、处理支付回调、验证支付结果等核心功能
|
||||
/// </summary>
|
||||
public class MiniProgramPay
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置对象,包含微信支付相关配置信息
|
||||
/// </summary>
|
||||
private Config _config;
|
||||
|
||||
/// <summary>
|
||||
/// 接口超时时间,单位: 秒,默认6秒
|
||||
/// </summary>
|
||||
private int _timeout = 6;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="config">配置对象,包含appid、商户号、密钥等信息</param>
|
||||
public MiniProgramPay(Config config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数(带超时设置)
|
||||
/// </summary>
|
||||
/// <param name="config">配置对象</param>
|
||||
/// <param name="timeout">接口超时时间,单位: 秒</param>
|
||||
public MiniProgramPay(Config config, int timeout)
|
||||
{
|
||||
_config = config;
|
||||
_timeout = timeout;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建JSAPI支付订单
|
||||
/// 调用微信统一下单接口,获取小程序调起支付所需的参数
|
||||
/// </summary>
|
||||
/// <param name="openid">用户标识,用户在商户appid下的唯一标识,必填</param>
|
||||
/// <param name="outTradeNo">商户订单号,商户系统内部订单号,要求32个字符内,必填</param>
|
||||
/// <param name="totalFee">订单总金额,单位: 分,必填</param>
|
||||
/// <param name="body">商品描述,如: "腾讯充值中心-QQ会员充值",必填</param>
|
||||
/// <param name="attach">附加数据,在查询API和支付通知中原样返回,可选</param>
|
||||
/// <param name="notifyUrl">支付结果通知回调地址,可选,不传则使用配置中的地址</param>
|
||||
/// <returns>MiniProgramPayResult对象,包含支付参数或错误信息</returns>
|
||||
public MiniProgramPayResult CreateJsApiOrder(string openid, string outTradeNo, int totalFee, string body, string attach = "", string notifyUrl = "")
|
||||
{
|
||||
MiniProgramPayResult result = new MiniProgramPayResult();
|
||||
try
|
||||
{
|
||||
// 参数校验 - openid必填
|
||||
if (string.IsNullOrEmpty(openid))
|
||||
{
|
||||
result.Success = false;
|
||||
result.Message = "openid不能为空";
|
||||
return result;
|
||||
}
|
||||
// 参数校验 - 商户订单号必填
|
||||
if (string.IsNullOrEmpty(outTradeNo))
|
||||
{
|
||||
result.Success = false;
|
||||
result.Message = "商户订单号不能为空";
|
||||
return result;
|
||||
}
|
||||
// 参数校验 - 支付金额必须大于0
|
||||
if (totalFee <= 0)
|
||||
{
|
||||
result.Success = false;
|
||||
result.Message = "支付金额必须大于0";
|
||||
return result;
|
||||
}
|
||||
// 参数校验 - 商品描述必填
|
||||
if (string.IsNullOrEmpty(body))
|
||||
{
|
||||
result.Success = false;
|
||||
result.Message = "商品描述不能为空";
|
||||
return result;
|
||||
}
|
||||
|
||||
// 构建统一下单请求参数
|
||||
WxPayData data = new WxPayData();
|
||||
data.SetValue("body", body); // 商品描述
|
||||
// 附加数据,可选
|
||||
if (!string.IsNullOrEmpty(attach))
|
||||
{
|
||||
data.SetValue("attach", attach);
|
||||
}
|
||||
data.SetValue("out_trade_no", outTradeNo); // 商户订单号
|
||||
data.SetValue("total_fee", totalFee); // 订单总金额,单位: 分
|
||||
data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss")); // 交易起始时间
|
||||
data.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss")); // 交易结束时间,10分钟后过期
|
||||
data.SetValue("trade_type", "JSAPI"); // 交易类型,小程序支付固定为JSAPI
|
||||
data.SetValue("openid", openid); // 用户标识
|
||||
|
||||
// 支付结果通知回调地址,可选
|
||||
if (!string.IsNullOrEmpty(notifyUrl))
|
||||
{
|
||||
data.SetValue("notify_url", HttpUtility.UrlEncode(notifyUrl));
|
||||
}
|
||||
|
||||
// 调用微信统一下单接口
|
||||
WxPayData unifiedOrderResult = WxPayApi.UnifiedOrder(_config, data, _timeout);
|
||||
|
||||
// 检查统一下单是否成功
|
||||
if (!unifiedOrderResult.IsSet("appid") || !unifiedOrderResult.IsSet("prepay_id") || unifiedOrderResult.GetValue("prepay_id").ToString() == "")
|
||||
{
|
||||
result.Success = false;
|
||||
result.Message = "统一下单失败";
|
||||
// 获取微信返回的错误信息
|
||||
if (unifiedOrderResult.IsSet("return_msg"))
|
||||
{
|
||||
result.Message = unifiedOrderResult.GetValue("return_msg").ToString();
|
||||
}
|
||||
// 获取错误码描述
|
||||
if (unifiedOrderResult.IsSet("err_code_des"))
|
||||
{
|
||||
result.ErrCodeDes = unifiedOrderResult.GetValue("err_code_des").ToString();
|
||||
}
|
||||
// 获取错误码
|
||||
if (unifiedOrderResult.IsSet("err_code"))
|
||||
{
|
||||
result.ErrCode = unifiedOrderResult.GetValue("err_code").ToString();
|
||||
}
|
||||
Log.Error("MiniProgramPay", "UnifiedOrder failed: " + unifiedOrderResult.ToJson());
|
||||
return result;
|
||||
}
|
||||
|
||||
// 获取预支付交易会话标识
|
||||
string prepayId = unifiedOrderResult.GetValue("prepay_id").ToString();
|
||||
result.PrepayId = prepayId;
|
||||
result.OutTradeNo = outTradeNo;
|
||||
|
||||
// 构建小程序调起支付所需的参数
|
||||
WxPayData jsApiParam = new WxPayData();
|
||||
jsApiParam.SetValue("appId", unifiedOrderResult.GetValue("appid")); // 公众号ID
|
||||
jsApiParam.SetValue("timeStamp", WxPayApi.GenerateTimeStamp()); // 时间戳
|
||||
jsApiParam.SetValue("nonceStr", WxPayApi.GenerateNonceStr()); // 随机字符串
|
||||
jsApiParam.SetValue("package", "prepay_id=" + prepayId); // 订单详情
|
||||
jsApiParam.SetValue("signType", "MD5"); // 签名类型
|
||||
jsApiParam.SetValue("paySign", jsApiParam.MakeSign(_config)); // 签名
|
||||
|
||||
// 设置返回结果
|
||||
result.Success = true;
|
||||
result.Message = "下单成功";
|
||||
result.TimeStamp = jsApiParam.GetValue("timeStamp").ToString();
|
||||
result.NonceStr = jsApiParam.GetValue("nonceStr").ToString();
|
||||
result.Package = jsApiParam.GetValue("package").ToString();
|
||||
result.PaySign = jsApiParam.GetValue("paySign").ToString();
|
||||
result.SignType = "MD5";
|
||||
|
||||
Log.Info("MiniProgramPay", "CreateJsApiOrder success, outTradeNo: " + outTradeNo);
|
||||
return result;
|
||||
}
|
||||
catch (WxPayException ex)
|
||||
{
|
||||
// 微信支付异常处理
|
||||
result.Success = false;
|
||||
result.Message = ex.Message;
|
||||
Log.Error("MiniProgramPay", "WxPayException: " + ex.Message);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 系统异常处理
|
||||
result.Success = false;
|
||||
result.Message = "系统异常";
|
||||
Log.Error("MiniProgramPay", "Exception: " + ex.ToString());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理支付回调通知
|
||||
/// 接收微信支付后台发送的支付结果,验证签名并返回处理结果
|
||||
/// </summary>
|
||||
/// <param name="inputStream">HTTP请求输入流,包含微信发送的XML数据</param>
|
||||
/// <returns>MiniProgramPayNotifyResult对象,包含支付结果信息</returns>
|
||||
public MiniProgramPayNotifyResult ProcessNotify(Stream inputStream)
|
||||
{
|
||||
MiniProgramPayNotifyResult result = new MiniProgramPayNotifyResult();
|
||||
try
|
||||
{
|
||||
// 读取微信支付后台发送的XML数据
|
||||
int count = 0;
|
||||
byte[] buffer = new byte[1024];
|
||||
StringBuilder builder = new StringBuilder();
|
||||
while ((count = inputStream.Read(buffer, 0, 1024)) > 0)
|
||||
{
|
||||
builder.Append(Encoding.UTF8.GetString(buffer, 0, count));
|
||||
}
|
||||
inputStream.Flush();
|
||||
inputStream.Close();
|
||||
inputStream.Dispose();
|
||||
|
||||
string notifyData = builder.ToString();
|
||||
Log.Info("MiniProgramPay", "Receive notify data: " + notifyData);
|
||||
|
||||
// 检查回调数据是否为空
|
||||
if (string.IsNullOrEmpty(notifyData))
|
||||
{
|
||||
result.Success = false;
|
||||
result.Message = "回调数据为空";
|
||||
result.ResultXml = BuildNotifyResponse(false, "回调数据为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
// 解析XML数据并验证签名
|
||||
WxPayData data = new WxPayData();
|
||||
try
|
||||
{
|
||||
data.FromXml(_config, notifyData);
|
||||
}
|
||||
catch (WxPayException ex)
|
||||
{
|
||||
// 签名验证失败
|
||||
result.Success = false;
|
||||
result.Message = "签名验证失败";
|
||||
result.ResultXml = BuildNotifyResponse(false, ex.Message);
|
||||
Log.Error("MiniProgramPay", "Sign check failed: " + ex.Message);
|
||||
return result;
|
||||
}
|
||||
|
||||
// 检查返回状态码是否为SUCCESS
|
||||
if (!data.IsSet("return_code") || data.GetValue("return_code").ToString() != "SUCCESS")
|
||||
{
|
||||
result.Success = false;
|
||||
result.Message = "返回状态码不正确";
|
||||
result.ResultXml = BuildNotifyResponse(false, "返回状态码不正确");
|
||||
return result;
|
||||
}
|
||||
|
||||
// 检查业务结果是否为SUCCESS
|
||||
if (!data.IsSet("result_code") || data.GetValue("result_code").ToString() != "SUCCESS")
|
||||
{
|
||||
result.Success = false;
|
||||
result.Message = "业务结果不正确";
|
||||
if (data.IsSet("err_code_des"))
|
||||
{
|
||||
result.Message = data.GetValue("err_code_des").ToString();
|
||||
}
|
||||
result.ResultXml = BuildNotifyResponse(false, result.Message);
|
||||
return result;
|
||||
}
|
||||
|
||||
// 检查微信订单号是否存在
|
||||
if (!data.IsSet("transaction_id"))
|
||||
{
|
||||
result.Success = false;
|
||||
result.Message = "微信订单号不存在";
|
||||
result.ResultXml = BuildNotifyResponse(false, "微信订单号不存在");
|
||||
return result;
|
||||
}
|
||||
|
||||
// 提取支付结果数据
|
||||
string transactionId = data.GetValue("transaction_id").ToString(); // 微信支付订单号
|
||||
string outTradeNo = data.IsSet("out_trade_no") ? data.GetValue("out_trade_no").ToString() : ""; // 商户订单号
|
||||
int totalFee = data.IsSet("total_fee") ? int.Parse(data.GetValue("total_fee").ToString()) : 0; // 订单总金额,单位: 分
|
||||
string openid = data.IsSet("openid") ? data.GetValue("openid").ToString() : ""; // 用户标识
|
||||
string timeEnd = data.IsSet("time_end") ? data.GetValue("time_end").ToString() : ""; // 支付完成时间
|
||||
string bankType = data.IsSet("bank_type") ? data.GetValue("bank_type").ToString() : ""; // 银行类型
|
||||
|
||||
// 验证订单真实性 - 通过查询订单接口验证
|
||||
bool queryResult = VerifyPaymentResult(transactionId);
|
||||
if (!queryResult)
|
||||
{
|
||||
result.Success = false;
|
||||
result.Message = "订单查询验证失败";
|
||||
result.ResultXml = BuildNotifyResponse(false, "订单查询验证失败");
|
||||
Log.Error("MiniProgramPay", "Order verify failed, transactionId: " + transactionId);
|
||||
return result;
|
||||
}
|
||||
|
||||
// 设置返回结果
|
||||
result.Success = true;
|
||||
result.Message = "支付成功";
|
||||
result.TransactionId = transactionId;
|
||||
result.OutTradeNo = outTradeNo;
|
||||
result.TotalFee = totalFee;
|
||||
result.OpenId = openid;
|
||||
result.TimeEnd = timeEnd;
|
||||
result.BankType = bankType;
|
||||
result.ResultXml = BuildNotifyResponse(true, "OK");
|
||||
|
||||
Log.Info("MiniProgramPay", "ProcessNotify success, transactionId: " + transactionId + ", outTradeNo: " + outTradeNo);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 系统异常处理
|
||||
result.Success = false;
|
||||
result.Message = "系统异常";
|
||||
result.ResultXml = BuildNotifyResponse(false, "系统异常");
|
||||
Log.Error("MiniProgramPay", "ProcessNotify exception: " + ex.ToString());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证支付结果(通过微信订单号)
|
||||
/// 调用微信订单查询接口验证订单是否支付成功
|
||||
/// </summary>
|
||||
/// <param name="transactionId">微信支付订单号</param>
|
||||
/// <returns>true: 验证成功 false: 验证失败</returns>
|
||||
public bool VerifyPaymentResult(string transactionId)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(transactionId))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 构建查询订单请求参数
|
||||
WxPayData req = new WxPayData();
|
||||
req.SetValue("transaction_id", transactionId);
|
||||
// 调用订单查询接口
|
||||
WxPayData res = WxPayApi.OrderQuery(_config, req, _timeout);
|
||||
|
||||
// 检查查询结果
|
||||
// return_code: 返回状态码,SUCCESS/FAIL
|
||||
// result_code: 业务结果,SUCCESS/FAIL
|
||||
// trade_state: 交易状态,SUCCESS—支付成功
|
||||
if (res.IsSet("return_code") && res.GetValue("return_code").ToString() == "SUCCESS" &&
|
||||
res.IsSet("result_code") && res.GetValue("result_code").ToString() == "SUCCESS" &&
|
||||
res.IsSet("trade_state") && res.GetValue("trade_state").ToString() == "SUCCESS")
|
||||
{
|
||||
Log.Info("MiniProgramPay", "VerifyPaymentResult success, transactionId: " + transactionId);
|
||||
return true;
|
||||
}
|
||||
|
||||
Log.Error("MiniProgramPay", "VerifyPaymentResult failed, transactionId: " + transactionId + ", response: " + res.ToJson());
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("MiniProgramPay", "VerifyPaymentResult exception: " + ex.ToString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证支付结果(通过商户订单号)
|
||||
/// 调用微信订单查询接口验证订单是否支付成功
|
||||
/// </summary>
|
||||
/// <param name="outTradeNo">商户订单号</param>
|
||||
/// <returns>true: 验证成功 false: 验证失败</returns>
|
||||
public bool VerifyPaymentResultByOutTradeNo(string outTradeNo)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(outTradeNo))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 构建查询订单请求参数
|
||||
WxPayData req = new WxPayData();
|
||||
req.SetValue("out_trade_no", outTradeNo);
|
||||
// 调用订单查询接口
|
||||
WxPayData res = WxPayApi.OrderQuery(_config, req, _timeout);
|
||||
|
||||
// 检查查询结果
|
||||
if (res.IsSet("return_code") && res.GetValue("return_code").ToString() == "SUCCESS" &&
|
||||
res.IsSet("result_code") && res.GetValue("result_code").ToString() == "SUCCESS" &&
|
||||
res.IsSet("trade_state") && res.GetValue("trade_state").ToString() == "SUCCESS")
|
||||
{
|
||||
Log.Info("MiniProgramPay", "VerifyPaymentResultByOutTradeNo success, outTradeNo: " + outTradeNo);
|
||||
return true;
|
||||
}
|
||||
|
||||
Log.Error("MiniProgramPay", "VerifyPaymentResultByOutTradeNo failed, outTradeNo: " + outTradeNo + ", response: " + res.ToJson());
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("MiniProgramPay", "VerifyPaymentResultByOutTradeNo exception: " + ex.ToString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询订单
|
||||
/// 通过微信订单号或商户订单号查询订单状态
|
||||
/// </summary>
|
||||
/// <param name="transactionId">微信支付订单号,与outTradeNo二选一</param>
|
||||
/// <param name="outTradeNo">商户订单号,与transactionId二选一</param>
|
||||
/// <returns>WxPayData对象,包含订单详细信息</returns>
|
||||
public WxPayData QueryOrder(string transactionId = "", string outTradeNo = "")
|
||||
{
|
||||
try
|
||||
{
|
||||
WxPayData req = new WxPayData();
|
||||
// 优先使用微信订单号查询
|
||||
if (!string.IsNullOrEmpty(transactionId))
|
||||
{
|
||||
req.SetValue("transaction_id", transactionId);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(outTradeNo))
|
||||
{
|
||||
req.SetValue("out_trade_no", outTradeNo);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WxPayException("transaction_id和out_trade_no至少填写一个");
|
||||
}
|
||||
|
||||
// 调用订单查询接口
|
||||
WxPayData res = WxPayApi.OrderQuery(_config, req, _timeout);
|
||||
return res;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("MiniProgramPay", "QueryOrder exception: " + ex.ToString());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭订单
|
||||
/// 当订单长时间未支付时,可调用此接口关闭订单
|
||||
/// 注意:订单生成后不能马上调用关闭订单接口,最短调用时间间隔为5分钟
|
||||
/// </summary>
|
||||
/// <param name="outTradeNo">商户订单号</param>
|
||||
/// <returns>WxPayData对象,包含关闭结果</returns>
|
||||
public WxPayData CloseOrder(string outTradeNo)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(outTradeNo))
|
||||
{
|
||||
throw new WxPayException("商户订单号不能为空");
|
||||
}
|
||||
|
||||
// 构建关闭订单请求参数
|
||||
WxPayData req = new WxPayData();
|
||||
req.SetValue("out_trade_no", outTradeNo);
|
||||
// 调用关闭订单接口
|
||||
WxPayData res = WxPayApi.CloseOrder(_config, req, _timeout);
|
||||
return res;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("MiniProgramPay", "CloseOrder exception: " + ex.ToString());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 申请退款
|
||||
/// 当交易发生错误或交易失败时,商户可通过此接口退款
|
||||
/// 注意:退款需要商户证书
|
||||
/// </summary>
|
||||
/// <param name="outTradeNo">商户订单号</param>
|
||||
/// <param name="outRefundNo">商户退款单号,商户系统内部的退款单号,要求唯一</param>
|
||||
/// <param name="totalFee">订单总金额,单位: 分</param>
|
||||
/// <param name="refundFee">退款金额,单位: 分,不能大于订单总金额</param>
|
||||
/// <param name="opUserId">操作员ID,可选,默认为商户号</param>
|
||||
/// <returns>WxPayData对象,包含退款结果</returns>
|
||||
public WxPayData Refund(string outTradeNo, string outRefundNo, int totalFee, int refundFee, string opUserId = "")
|
||||
{
|
||||
try
|
||||
{
|
||||
// 参数校验
|
||||
if (string.IsNullOrEmpty(outTradeNo))
|
||||
{
|
||||
throw new WxPayException("商户订单号不能为空");
|
||||
}
|
||||
if (string.IsNullOrEmpty(outRefundNo))
|
||||
{
|
||||
throw new WxPayException("商户退款单号不能为空");
|
||||
}
|
||||
if (totalFee <= 0)
|
||||
{
|
||||
throw new WxPayException("订单总金额必须大于0");
|
||||
}
|
||||
if (refundFee <= 0)
|
||||
{
|
||||
throw new WxPayException("退款金额必须大于0");
|
||||
}
|
||||
if (refundFee > totalFee)
|
||||
{
|
||||
throw new WxPayException("退款金额不能大于订单总金额");
|
||||
}
|
||||
|
||||
// 构建退款请求参数
|
||||
WxPayData req = new WxPayData();
|
||||
req.SetValue("out_trade_no", outTradeNo); // 商户订单号
|
||||
req.SetValue("out_refund_no", outRefundNo); // 商户退款单号
|
||||
req.SetValue("total_fee", totalFee); // 订单总金额,单位: 分
|
||||
req.SetValue("refund_fee", refundFee); // 退款金额,单位: 分
|
||||
// 操作员ID,默认为商户号
|
||||
if (string.IsNullOrEmpty(opUserId))
|
||||
{
|
||||
req.SetValue("op_user_id", _config.webPARTNER);
|
||||
}
|
||||
else
|
||||
{
|
||||
req.SetValue("op_user_id", opUserId);
|
||||
}
|
||||
|
||||
// 调用退款接口
|
||||
WxPayData res = WxPayApi.Refund(_config, req, _timeout);
|
||||
return res;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("MiniProgramPay", "Refund exception: " + ex.ToString());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构建回调通知响应XML
|
||||
/// 用于返回给微信支付后台的处理结果
|
||||
/// </summary>
|
||||
/// <param name="success">处理是否成功</param>
|
||||
/// <param name="message">消息内容</param>
|
||||
/// <returns>XML格式的响应字符串</returns>
|
||||
public string BuildNotifyResponse(bool success, string message)
|
||||
{
|
||||
WxPayData res = new WxPayData();
|
||||
res.SetValue("return_code", success ? "SUCCESS" : "FAIL");
|
||||
res.SetValue("return_msg", message);
|
||||
return res.ToXml();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成商户订单号
|
||||
/// 格式: 商户号 + 时间戳 + 3位随机数
|
||||
/// </summary>
|
||||
/// <param name="config">配置对象</param>
|
||||
/// <returns>商户订单号字符串</returns>
|
||||
public static string GenerateOutTradeNo(Config config)
|
||||
{
|
||||
var ran = new Random();
|
||||
return string.Format("{0}{1}{2}", config.webPARTNER, DateTime.Now.ToString("yyyyMMddHHmmss"), ran.Next(999));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取支付结果JSON字符串
|
||||
/// 用于返回给前端小程序的支付参数
|
||||
/// </summary>
|
||||
/// <param name="result">支付结果对象</param>
|
||||
/// <returns>JSON格式的字符串</returns>
|
||||
public string GetPayResultJson(MiniProgramPayResult result)
|
||||
{
|
||||
if (result.Success)
|
||||
{
|
||||
// 成功时返回支付参数
|
||||
return JsonMapper.ToJson(new
|
||||
{
|
||||
status = 1, // 状态码,1表示成功
|
||||
msg = result.Message, // 消息
|
||||
timeStamp = result.TimeStamp, // 时间戳
|
||||
noncestr = result.NonceStr, // 随机字符串
|
||||
package = result.Package, // 订单详情
|
||||
paySign = result.PaySign, // 签名
|
||||
signType = result.SignType, // 签名类型
|
||||
prepayId = result.PrepayId, // 预支付ID
|
||||
outTradeNo = result.OutTradeNo // 商户订单号
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
// 失败时返回错误信息
|
||||
return JsonMapper.ToJson(new
|
||||
{
|
||||
status = 0, // 状态码,0表示失败
|
||||
msg = result.Message, // 错误消息
|
||||
errCode = result.ErrCode, // 错误码
|
||||
errCodeDes = result.ErrCodeDes // 错误描述
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -228,7 +228,7 @@
|
||||
<aliAPP_PRIVATE_KEY0 value="MIIEpQIBAAKCAQEAifSSbAM1LsUszjqx3MvtwMmTk3QC6O5/KMkZCJD0JS0TFD/psq3d2baCmiA7uJT9y9cRLivG+QwIfRM/ldz7j6IcSk2zEDkpbEgzUmPO/tnmkvwSztOn4VM4GKTzqy2fRJcncKZBS1GM+Ifxa8Lyz8aNPmuXPvljBo88w2QqjQ1J4qW9Ql4U7PZ5AG7nai7PP9AjJQIz3JgFdO5VyHRiPYFQU12bSFtv3r3X44wRDTwdeJwN89JeP853GQhysJ9ry+lg5HFcaZkln6UxRFvMWev7V0W4SD7HdCET0q7zfpRYHRMaqBee1hI90uvmiJPWFDcPwCJpDJYk0wJb1U5UJQIDAQABAoIBAF25oKTrhP1Sjn9KFz7H+a5qBO4/+h4gspmWDoDoYkbDmdu/FFoFj9zzB0YJMinUZ51Ob2ir61GWYEoBgsihSvOpkojUwxv5ie/8GYoXLzGr/t/LjEeiOsN2E32Cy913cGZcPzpkaaXvMNRFH7szxl1tKtbGqAnryuBQ/lpNOi97YUjoIRodcS3qmFzicRnag/Pyzw0+I6l4fH9Inh1u0680R3f4D9bjEgZxe5//syBhtzb1R6u5uhEHOZ0bKAkhwfpfwnkfivJIcDF88DGHbIdgyvv14c6rsuC3JXhXuurHBR8kYbAO1rtxs4RdVUPpuTzCnTrZVVYSpbwajX0+4R0CgYEAwZC5o+JCU/006/rI3+tA3UiZxFliD4VLzd4Zwg7piVj56QXjKWiJj2c3KQsRJWzfVTkjmW6GRtnpIUj6usp8tXnK1L4GugLGbgzVRdaf1sFFf7+3o7ouv+YuXWdJhiCRX8JrwfNT+WQEioys2kn8ghq5EtKTn0kUssVAkOF2lGsCgYEAtnP2kDTRE5FDVaI0eCyjURb8ZbTDng5bkw+Aez4mp4bRFhUp86pjtyRH4UREAWZMYA/KzAj11mCgpx2X/rKXgLSH1yMBx2a0ton65kqlkH23qotjwNOOC64oN5NDO6RXP3+b7cdWjhJlMR10MX0liBAfkwA0xwTQsW1RsJj8Xa8CgYEAjxAehQgXqef9k2RZz1YbLPIZ5EuD9KC6dD/xncJTzVXb7+SQDuzarwjEditd0uFy95QxwZc022z3p8g+uIwsPBz2UuLYKecfLfuCLgoBPUK/0TmryvEy2FaSciqC5wVvLO2Po1vq9up7iMOMhhIk9Sw3GbhVr2beS3sKy4o4kF0CgYEAl1sl3MVj+GaWRFDWVCc7qIZ4BWtqqBDjGOFQRWzupiUqCLav4aqlJAXd91spSzvw+fO/2XlJb3kjbN8Y+zpugl/BHNC2phNmsNNQJ4EfTflsxvbxXsJhYQEt7cSljrGri0qyMRQfkqZh+dekT3WxD+nIN6uBHOS6t6Wnkeen25MCgYEApObseYd0KVNFMLWr7iVWLoHe7n0nYZZL13WIbEru9JKsbaZdRsP6G3GxaJHDLrf2r6US+MvIBQOU95Y5Fp2kEXw1JD9/JECUjjRE/pzoNt3qO0WAVGFphOMcxzc4XsQ6LoK1b4DSXzOGj9ESjNkAPhbEK89usG49G8/C/b53F34=" des="开发者应用私钥" />
|
||||
<aliPAY_PUBLIC_KEY0 value="MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCnxj/9qwVfgoUh/y2W89L6BkRAFljhNhgPdyPuBV64bfQNN1PjbCzkIM6qRdKBoLPXmKKMiFYnkd6rAoprih3/PrQEB/VsW8OoM8fxn67UDYuyBTqA23MML9q1+ilIZwBC2AQ2UBVOrFXfFl75p6/B5KsiNG9zpgmLCUYuLkxpLQIDAQAB" des="开发者应用公钥" />
|
||||
<webXAppID value="wx7899fda6c28b65ee" des="微信小程序AppID" />
|
||||
<webXAppSecret value="9320580e35e1e1d9b226270484ce8711" des="微信小程序AppSecret" />
|
||||
<webXAppSecret value="75a052a32fddee48e7a95b3d908cee8d" des="微信小程序AppSecret" />
|
||||
<webXaccess_token value="91_P-MAhXG1n6nbopPaaTsbqVBguCa_YCMea_AgDKz0ySkKFcIKn627w3PhImohwm7uXCj4XkeCqPXTQrJj_H4QOExkrLzhT0-YuvfXCST9q7swdAJpeP09RXrlgusQDHbAJAKXB" des="小程序access_token" />
|
||||
<webXaccess_token_time value="2025-04-29 09:35:28" des="小程序access_token_time" />
|
||||
<webToken value="hxgcandgengliu" des="微信Token" />
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<DeleteExistingFiles>false</DeleteExistingFiles>
|
||||
<ExcludeApp_Data>false</ExcludeApp_Data>
|
||||
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
|
||||
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
|
||||
<LastUsedPlatform>Any CPU</LastUsedPlatform>
|
||||
<PublishProvider>FileSystem</PublishProvider>
|
||||
<PublishUrl>D:\renyipublic</PublishUrl>
|
||||
<WebPublishMethod>FileSystem</WebPublishMethod>
|
||||
<_TargetId>Folder</_TargetId>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -329,10 +329,10 @@
|
||||
</div>
|
||||
<span class="no">
|
||||
<ul class="menu" style="display:none;">
|
||||
<!--<li><a target="mainFrame" href="/Admin_Member_business0_list.aspx">申请线上门店列表</a></li>
|
||||
<li><a target="mainFrame" href="/Admin_Member_List0.aspx">联盟部列表</a></li>
|
||||
<li><a target="mainFrame" href="/Admin_Member_Products_SJ_Seef.aspx?t=2">联盟部商品列表</a></li>
|
||||
<li><a target="mainFrame" href="/Admin_Member_Products_SJ_Orders.aspx?t=2">联盟部订单列表</a></li>-->
|
||||
<li><a target="mainFrame" href="/Admin_Member_business0_list.aspx">申请线上门店列表</a></li>
|
||||
<%-- <li><a target="mainFrame" href="/Admin_Member_List0.aspx">联盟部列表</a></li>--%>
|
||||
<%-- <li><a target="mainFrame" href="/Admin_Member_Products_SJ_Seef.aspx?t=2">联盟部商品列表</a></li>
|
||||
<li><a target="mainFrame" href="/Admin_Member_Products_SJ_Orders.aspx?t=2">联盟部订单列表</a></li>--%>
|
||||
|
||||
<!-- <li><a target="mainFrame" href="/Admin_Member_Products6.aspx">联盟部商品列表</a></li>
|
||||
|
||||
|
||||
@@ -274,7 +274,7 @@ namespace Mtxfw.VipSite
|
||||
case "getmyproducts": data = getmyproducts(context); break;
|
||||
case "getqiandao": data = getqiandao(context); break;
|
||||
case "qiandao": data = qiandao(context); break;
|
||||
case "getmytgm": data = getmytgm(context); break;
|
||||
case "getmytgm": data = getmytgm2(context); break;
|
||||
case "appdeclaration": data = appdeclaration(context); break;
|
||||
case "kttgy": data = kttgy(context); break;
|
||||
case "getkttgylist": data = getkttgylist(context); break;
|
||||
@@ -8699,7 +8699,7 @@ namespace Mtxfw.VipSite
|
||||
}
|
||||
|
||||
}
|
||||
if (strdata.Substring(strdata.Length - 3, 3) != "]},")
|
||||
if (i > 0 && strdata.Substring(strdata.Length - 3, 3) != "]},")
|
||||
{
|
||||
if (strdata.Substring(strdata.Length - 1, 1) == ",")
|
||||
{
|
||||
@@ -8713,7 +8713,7 @@ namespace Mtxfw.VipSite
|
||||
}
|
||||
}
|
||||
ds.Clear();
|
||||
strdata += "]";
|
||||
strdata += "]";
|
||||
}
|
||||
if (strdata != "")
|
||||
{
|
||||
@@ -8725,8 +8725,8 @@ namespace Mtxfw.VipSite
|
||||
int Limit = 12;
|
||||
|
||||
Int32 Recount = 0;//
|
||||
System.Data.DataSet Ds_ = daobusiness.GetDataSet(groupby, strOrder, "id,UserId,CompanyName,picture,Companyaddress,ycoo,xcoo,dbo.GetDistance(" + latitude + "," + longitude + ",xcoo,ycoo) as distance", "", "utype='0' and (seef=1 or seef0=1) and showpic=0" + strsql + "", Start, Limit, out Recount);
|
||||
|
||||
//System.Data.DataSet Ds_ = daobusiness.GetDataSet(groupby, strOrder, "id,UserId,CompanyName,picture,Companyaddress,ycoo,xcoo,dbo.GetDistance(" + latitude + "," + longitude + ",xcoo,ycoo) as distance", "", "utype='0' and (seef=1 or seef0=1) and showpic=0" + strsql + "", Start, Limit, out Recount);
|
||||
System.Data.DataSet Ds_ = daobusiness.GetDataSet(groupby, strOrder, "id,UserId,CompanyName,picture,Companyaddress,ycoo,xcoo,ContactPhone,dbo.GetDistance(" + latitude + "," + longitude + ",xcoo,ycoo) as distance", "", "utype='2' and (seef=1 or seef0=1) and showpic=0" + strsql + "", Start, Limit, out Recount);
|
||||
if (Ds_.Tables[1].Rows.Count > 0)
|
||||
{
|
||||
int j = 0;
|
||||
@@ -8735,6 +8735,7 @@ namespace Mtxfw.VipSite
|
||||
string id = drv["id"].ToString();
|
||||
string UserId = drv["UserId"].ToString();
|
||||
string name = drv["CompanyName"].ToString();
|
||||
string Phone = drv["ContactPhone"].ToString();
|
||||
string images = drv["picture"].ToString().Split('|')[0].Split(',')[0];
|
||||
if (images != "")
|
||||
{
|
||||
@@ -8762,7 +8763,7 @@ namespace Mtxfw.VipSite
|
||||
{
|
||||
strdistance = distance.ToString("f0") + "m";
|
||||
}
|
||||
strdata += "{\"_id\":\"" + id + "\",\"showpic\":\"0\",\"name\":\"" + Mtxfw.Utility.Common.ReplaceString(name) + "\",\"address\":\"" + Mtxfw.Utility.Common.ReplaceString(address) + "\",\"distance\":\"" + strdistance + "\",\"lon\":\"" + lon + "\",\"lat\":\"" + lat + "\",\"image\":\"" + images + "\"";
|
||||
strdata += "{\"_id\":\"" + id + "\",\"showpic\":\"0\",\"name\":\"" + Mtxfw.Utility.Common.ReplaceString(name) + "\",\"address\":\"" + Mtxfw.Utility.Common.ReplaceString(address) + "\",\"distance\":\"" + strdistance + "\",\"lon\":\"" + lon + "\",\"lat\":\"" + lat + "\",\"phone\":\"" + Phone + "\",\"image\":\"" + images + "\"";
|
||||
strdata += ",\"products\":[";
|
||||
|
||||
/*DataSet Ds_Product0 = daoProduct.GetList1("top 3 P_ID,P_NAME,P_images", "gtype=" + gtype + " And IFDelete=0 And P_qgproduct=1 And P_State=N'已处理' And P_UserID=" + UserId + " And (Select count(c.G_ID) From P_Guige c where c.G_PID=P_ID And G_KC>0)>0 order by P_IFTop Desc,P_HITED Desc");
|
||||
@@ -8931,7 +8932,7 @@ namespace Mtxfw.VipSite
|
||||
{
|
||||
strdistance = distance.ToString("f0") + "m";
|
||||
}
|
||||
data += ",\"_id\":\"" + bmodel.Id + "\",\"showpic\":\"" + bmodel.showpic + "\",\"name\":\"" + Mtxfw.Utility.Common.ReplaceString(bmodel.CompanyName) + "\",\"address\":\"" + Mtxfw.Utility.Common.ReplaceString(bmodel.Companyaddress) + "\",\"fwbody\":\"" + Mtxfw.Utility.Common.ReplaceString(bmodel.BusinessRange) + "\",\"distance\":\"" + strdistance + "\",\"lon\":\"" + bmodel.xcoo + "\",\"lat\":\"" + bmodel.ycoo + "\"";
|
||||
data += ",\"_id\":\"" + bmodel.Id + "\",\"showpic\":\"" + bmodel.showpic + "\",\"name\":\"" + Mtxfw.Utility.Common.ReplaceString(bmodel.CompanyName) + "\",\"address\":\"" + Mtxfw.Utility.Common.ReplaceString(bmodel.Companyaddress) + "\",\"fwbody\":\"" + Mtxfw.Utility.Common.ReplaceString(bmodel.BusinessRange) + "\",\"distance\":\"" + strdistance + "\",\"lon\":\"" + bmodel.xcoo + "\",\"phone\":\"" + bmodel.ContactPhone + "\",\"lat\":\"" + bmodel.ycoo + "\"";
|
||||
data += ",\"productlist\":[";
|
||||
if (bmodel.utype == "0")
|
||||
{
|
||||
@@ -9631,10 +9632,10 @@ namespace Mtxfw.VipSite
|
||||
Ds_Product.Clear();
|
||||
strdata += "]";
|
||||
|
||||
strdata += (userinfo + ",\"IFAuto\":\"" + IFAuto + "\",\"IFYGM\":" + IFYGM + ",\"dlMemberId\":\"0\",\"province\":\"" + province + "\",\"city\":\"" + city + "\",\"county\":\"" + county + "\",\"Address\":\"" + strAddress + "\",\"servermsg\":\"" + Mtxfw.Utility.Common.ReplaceString(Mtxfw.Utility.Common.InputText(config.ServerMsg)) + "\",\"webname\":\"" + config.webName + "\"");
|
||||
strdata += (userinfo +",\"IFAuto\":\"" + IFAuto + "\",\"IFYGM\":" + IFYGM + ",\"dlMemberId\":\"0\",\"province\":\"" + province + "\",\"city\":\"" + city + "\",\"county\":\"" + county + "\",\"Address\":\"" + strAddress + "\",\"servermsg\":\"" + Mtxfw.Utility.Common.ReplaceString(Mtxfw.Utility.Common.InputText(config.ServerMsg)) + "\",\"webname\":\"" + config.webName + "\"");
|
||||
}
|
||||
|
||||
data = "{\"status\":1," + strdata + "}";
|
||||
//ifxn 是否显示轮播菜单 0不显示,1显示
|
||||
data = "{\"status\":1," + "\"ifxn\":0," + strdata + "}";
|
||||
}
|
||||
}
|
||||
return data;
|
||||
@@ -10760,7 +10761,8 @@ namespace Mtxfw.VipSite
|
||||
if (umodel != null)
|
||||
{
|
||||
|
||||
if (umodel.LoginId2 == LoginId)
|
||||
//if (umodel.LoginId2 == LoginId)
|
||||
if (1 == 1)
|
||||
{
|
||||
string NCName = (umodel.NCName == "" ? umodel.RealName : umodel.NCName);
|
||||
string UserPic = umodel.UserPic;
|
||||
@@ -10845,7 +10847,118 @@ namespace Mtxfw.VipSite
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region //获取我的推广码-----------------------------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// 获取我的推广码
|
||||
/// </summary>
|
||||
protected string getmytgm2(HttpContext context)
|
||||
{
|
||||
string data = "{\"status\":0}";
|
||||
int userId = 0;
|
||||
if (!String.IsNullOrEmpty(context.Request["userId"]) && !String.IsNullOrEmpty(context.Request["LoginId"]))
|
||||
{
|
||||
userId = Convert.ToInt32(context.Request["userId"].ToString());
|
||||
if (userId == 0)
|
||||
{
|
||||
data = "{\"status\":0,\"msg\":\"参数错误\"}";
|
||||
return data;
|
||||
}
|
||||
string LoginId = HttpUtility.UrlDecode(context.Request["LoginId"].ToString());
|
||||
|
||||
Mtxfw.Model.user_info umodel = daoUser.GetModel(userId);
|
||||
if (umodel != null)
|
||||
{
|
||||
|
||||
if (umodel.LoginId2 == LoginId)
|
||||
{
|
||||
string NCName = (umodel.NCName == "" ? umodel.RealName : umodel.NCName);
|
||||
string UserPic = umodel.UserPic;
|
||||
string QRcode = umodel.EWMPic2;
|
||||
string yqm = Mtxfw.Utility.Security.encrypt(umodel.Id).ToString();
|
||||
if (QRcode == "")
|
||||
{
|
||||
|
||||
bool ifb = true;
|
||||
DateTime dt1 = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||
if (config.webXaccess_token != "" && config.webXaccess_token_time != "")
|
||||
{
|
||||
|
||||
DateTime dt2 = Convert.ToDateTime(Convert.ToDateTime(config.webXaccess_token_time).AddMinutes(100).ToString("yyyy-MM-dd HH:mm:ss"));
|
||||
if (dt1 > dt2)
|
||||
{
|
||||
ifb = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ifb = false;
|
||||
}
|
||||
if (!ifb)
|
||||
{
|
||||
|
||||
Mtxfw.Utility.WXaccess_token ac = Mtxfw.Utility.Common.getxaccess_token(config.webXAppID, config.webXAppSecret);
|
||||
config.webXaccess_token = ac.access_token;
|
||||
config.webXaccess_token_time = dt1.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
config.Save();
|
||||
}
|
||||
//string URL = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" + config.webXaccess_token;
|
||||
//string json = "{\"path\":\"pages/index/index?tguid=" + Mtxfw.Utility.Security.encrypt(umodel.Id) + "\"}";
|
||||
string URL = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + config.webXaccess_token;
|
||||
string json = "{\"scene\":\"" + Mtxfw.Utility.Security.encrypt(umodel.Id) + "\",\"page\":\"pages/index/index\"}";
|
||||
byte[] bytes = Mtxfw.Utility.Common.GetResponsebyte(json, URL);
|
||||
string str = System.Text.Encoding.Default.GetString(bytes);
|
||||
//Mtxfw.Utility.Common.WriteHtml("/weixin/errcode.txt", str);
|
||||
if (str.IndexOf("errcode") != -1)
|
||||
{
|
||||
Mtxfw.Utility.WXaccess_token ac = Mtxfw.Utility.Common.getxaccess_token(config.webXAppID, config.webXAppSecret);
|
||||
config.webXaccess_token = ac.access_token;
|
||||
config.webXaccess_token_time = dt1.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
config.Save();
|
||||
URL = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + ac.access_token;
|
||||
bytes = Mtxfw.Utility.Common.GetResponsebyte(json, URL);
|
||||
str = BitConverter.ToString(bytes);
|
||||
//Mtxfw.Utility.Common.WriteHtml("/weixin/errcode0.txt", str);
|
||||
}
|
||||
|
||||
/*var filepath = "/Files/grimage/" + umodel.Id + "/";
|
||||
//创建保存位置
|
||||
if (!Directory.Exists(context.Server.MapPath(filepath)))
|
||||
{
|
||||
Directory.CreateDirectory(context.Server.MapPath(filepath));
|
||||
}
|
||||
string filename = filepath + "ewm.jpg";
|
||||
//写入文件
|
||||
System.IO.File.WriteAllBytes(context.Server.MapPath(filename), bytes);
|
||||
|
||||
string ewmpic = "data:image/png;base64," + Mtxfw.Utility.Common.ImageToBase64(context.Server.MapPath(filename));*/
|
||||
string ewmpic = "data:image/png;base64," + Convert.ToBase64String(bytes);
|
||||
new Mtxfw.DAL.user_info().UpdatePassword("EWMPic2", ewmpic, umodel.Id);
|
||||
umodel.EWMPic2 = ewmpic;
|
||||
}
|
||||
//Mtxfw.Utility.Common.WriteHtml("/weixin/EWMPic.txt", umodel.EWMPic2);
|
||||
data = "{\"status\":1,\"QRcode\":\"" + umodel.EWMPic2 + "\",\"minQRcode\":\"" + umodel.EWMPic2 + "\",\"yqm\":\"" + yqm + "\"}";
|
||||
}
|
||||
else
|
||||
{
|
||||
data = "{\"status\":0,\"msg\":\"您未登录\"}";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
data = "{\"status\":0,\"msg\":\"参数错误\"}";
|
||||
return data;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
data = "{\"status\":0,\"msg\":\"参数为空\"}";
|
||||
return data;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region //申请代理-----------------------------------------------------------------------------------------
|
||||
@@ -16426,7 +16539,10 @@ namespace Mtxfw.VipSite
|
||||
var webName = config.webName;//仁E森命or 银花支付
|
||||
//0官方支付1汇付支付
|
||||
var isHfPay = 1;
|
||||
if (webName.Contains("仁E森命"))
|
||||
if (webName.Contains("仁E森命"))
|
||||
{
|
||||
isHfPay = 0;
|
||||
}
|
||||
///银花支付目前进的这里
|
||||
strProductName = strProductName.Replace("%", "度").Replace(" ", "");
|
||||
if (strProductName.Length > 120)
|
||||
@@ -16471,68 +16587,148 @@ namespace Mtxfw.VipSite
|
||||
|
||||
|
||||
// 注释掉原有代码,改用HuifuPaymentService
|
||||
|
||||
string sys_id = config.hfpaysys_id;
|
||||
string product_id = config.hfpayproduct_id;
|
||||
string req_date = dt.ToString("yyyyMMdd");
|
||||
string req_seq_id = PayID;
|
||||
string huifu_id = config.hfpayMerchantID;
|
||||
string goods_desc = body;
|
||||
string trade_type = "T_MINIAPP";//T_JSAPI: 微信公众号 T_MINIAPP: 微信小程序 A_JSAPI: 支付宝 A_NATIVE: 支付宝正扫 U_NATIVE: 银联正扫 U_JSAPI: 银联JS D_NATIVE: 数字人民币正扫 T_H5:微信直连H5支付 T_APP:微信APP支付 T_NATIVE:微信正扫
|
||||
string wx_data = "{\\\"sub_appid\\\":\\\"" + config.webXAppID + "\\\",\\\"sub_openid\\\":\\\"" + openid + "\\\"}";
|
||||
string trans_amt = PayZSubTotal.ToString("f2");
|
||||
string time_expire = dt.AddMinutes(10).ToString("yyyyMMddHHmmss");
|
||||
string notify_url = config.webUrl + "/pay/hfpay_notify_url.aspx";
|
||||
SortedDictionary<string, string> pay_dic = new SortedDictionary<string, string>();
|
||||
pay_dic.Add("req_date", req_date);
|
||||
pay_dic.Add("req_seq_id", req_seq_id);
|
||||
pay_dic.Add("huifu_id", huifu_id);
|
||||
pay_dic.Add("goods_desc", goods_desc);
|
||||
pay_dic.Add("trade_type", trade_type);
|
||||
pay_dic.Add("wx_data", wx_data);
|
||||
pay_dic.Add("trans_amt", trans_amt);
|
||||
pay_dic.Add("time_expire", time_expire);
|
||||
pay_dic.Add("notify_url", notify_url);
|
||||
string get_PaySign = Mtxfw.Utility.Interface_WxPay.BuildRequest0(pay_dic, config.hfpayPrivateKey);
|
||||
string strq = "{";
|
||||
strq += "\"sys_id\":\"" + sys_id + "\",";
|
||||
strq += "\"product_id\":\"" + product_id + "\",";
|
||||
strq += "\"data\":{";
|
||||
strq += "\"req_date\":\"" + req_date + "\",";
|
||||
strq += "\"req_seq_id\":\"" + req_seq_id + "\",";
|
||||
strq += "\"huifu_id\":\"" + huifu_id + "\",";
|
||||
strq += "\"goods_desc\":\"" + goods_desc + "\",";
|
||||
strq += "\"trade_type\":\"" + trade_type + "\",";
|
||||
strq += "\"wx_data\":\"" + wx_data + "\",";
|
||||
strq += "\"trans_amt\":\"" + trans_amt + "\",";
|
||||
strq += "\"time_expire\":\"" + time_expire + "\",";
|
||||
strq += "\"notify_url\":\"" + notify_url + "\"";
|
||||
strq += "}";
|
||||
strq += ",\"sign\":\"" + get_PaySign + "\"";
|
||||
strq += "}";
|
||||
Mtxfw.Utility.Common.WriteHtml("/weixin/postData1.txt", strq);
|
||||
string strResult = Mtxfw.Utility.Common.getPage2("https://api.huifu.com/v3/trade/payment/jspay", "", "utf-8", true, true, strq);
|
||||
Mtxfw.Utility.Common.WriteHtml("/weixin/resData.txt", strResult);
|
||||
huifuresult hr = (huifuresult)FromhuifuresultJson(strResult);
|
||||
Mtxfw.Utility.Common.WriteHtml("/weixin/xapiajaxstrstart.txt", hr.ToString());
|
||||
if (hr.data.resp_code == "00000100")
|
||||
//如果是汇付
|
||||
if (isHfPay == 1)
|
||||
{
|
||||
huifuresult2 hr0 = (huifuresult2)Fromhuifuresult2Json(strResult);
|
||||
string pay_info = hr0.data.pay_info;
|
||||
var zflx = "2";
|
||||
hjpay_rc_Result hjrc_Result = (hjpay_rc_Result)Fromhjpay_rc_Result(pay_info);
|
||||
data = "{\"status\":1,\"msg\":\"正在支付中...\",\"timeStamp\":\"" + hjrc_Result.timeStamp + "\",\"noncestr\":\"" + hjrc_Result.nonceStr + "\",\"zftype\":\"" + zflx + "\",\"ResultId\":\"" + hjrc_Result.timeStamp + "\",\"package\":\"" + hjrc_Result.package + "\",\"paySign\":\"" + hjrc_Result.paySign + "\",\"signType\":\"" + hjrc_Result.signType + "\"}";
|
||||
Mtxfw.Utility.Common.WriteHtml("/weixin/xapiajaxstrstart2.txt", data);
|
||||
b = false;
|
||||
string sys_id = config.hfpaysys_id;
|
||||
string product_id = config.hfpayproduct_id;
|
||||
string req_date = dt.ToString("yyyyMMdd");
|
||||
string req_seq_id = PayID;
|
||||
string huifu_id = config.hfpayMerchantID;
|
||||
string goods_desc = body;
|
||||
string trade_type = "T_MINIAPP";//T_JSAPI: 微信公众号 T_MINIAPP: 微信小程序 A_JSAPI: 支付宝 A_NATIVE: 支付宝正扫 U_NATIVE: 银联正扫 U_JSAPI: 银联JS D_NATIVE: 数字人民币正扫 T_H5:微信直连H5支付 T_APP:微信APP支付 T_NATIVE:微信正扫
|
||||
string wx_data = "{\\\"sub_appid\\\":\\\"" + config.webXAppID + "\\\",\\\"sub_openid\\\":\\\"" + openid + "\\\"}";
|
||||
string trans_amt = PayZSubTotal.ToString("f2");
|
||||
string time_expire = dt.AddMinutes(10).ToString("yyyyMMddHHmmss");
|
||||
string notify_url = config.webUrl + "/pay/hfpay_notify_url.aspx";
|
||||
SortedDictionary<string, string> pay_dic = new SortedDictionary<string, string>();
|
||||
pay_dic.Add("req_date", req_date);
|
||||
pay_dic.Add("req_seq_id", req_seq_id);
|
||||
pay_dic.Add("huifu_id", huifu_id);
|
||||
pay_dic.Add("goods_desc", goods_desc);
|
||||
pay_dic.Add("trade_type", trade_type);
|
||||
pay_dic.Add("wx_data", wx_data);
|
||||
pay_dic.Add("trans_amt", trans_amt);
|
||||
pay_dic.Add("time_expire", time_expire);
|
||||
pay_dic.Add("notify_url", notify_url);
|
||||
string get_PaySign = Mtxfw.Utility.Interface_WxPay.BuildRequest0(pay_dic, config.hfpayPrivateKey);
|
||||
string strq = "{";
|
||||
strq += "\"sys_id\":\"" + sys_id + "\",";
|
||||
strq += "\"product_id\":\"" + product_id + "\",";
|
||||
strq += "\"data\":{";
|
||||
strq += "\"req_date\":\"" + req_date + "\",";
|
||||
strq += "\"req_seq_id\":\"" + req_seq_id + "\",";
|
||||
strq += "\"huifu_id\":\"" + huifu_id + "\",";
|
||||
strq += "\"goods_desc\":\"" + goods_desc + "\",";
|
||||
strq += "\"trade_type\":\"" + trade_type + "\",";
|
||||
strq += "\"wx_data\":\"" + wx_data + "\",";
|
||||
strq += "\"trans_amt\":\"" + trans_amt + "\",";
|
||||
strq += "\"time_expire\":\"" + time_expire + "\",";
|
||||
strq += "\"notify_url\":\"" + notify_url + "\"";
|
||||
strq += "}";
|
||||
strq += ",\"sign\":\"" + get_PaySign + "\"";
|
||||
strq += "}";
|
||||
Mtxfw.Utility.Common.WriteHtml("/weixin/postData1.txt", strq);
|
||||
string strResult = Mtxfw.Utility.Common.getPage2("https://api.huifu.com/v3/trade/payment/jspay", "", "utf-8", true, true, strq);
|
||||
Mtxfw.Utility.Common.WriteHtml("/weixin/resData.txt", strResult);
|
||||
huifuresult hr = (huifuresult)FromhuifuresultJson(strResult);
|
||||
Mtxfw.Utility.Common.WriteHtml("/weixin/xapiajaxstrstart.txt", hr.ToString());
|
||||
if (hr.data.resp_code == "00000100")
|
||||
{
|
||||
huifuresult2 hr0 = (huifuresult2)Fromhuifuresult2Json(strResult);
|
||||
string pay_info = hr0.data.pay_info;
|
||||
var zflx = "2";
|
||||
hjpay_rc_Result hjrc_Result = (hjpay_rc_Result)Fromhjpay_rc_Result(pay_info);
|
||||
data = "{\"status\":1,\"msg\":\"正在支付中...\",\"timeStamp\":\"" + hjrc_Result.timeStamp + "\",\"noncestr\":\"" + hjrc_Result.nonceStr + "\",\"zftype\":\"" + zflx + "\",\"ResultId\":\"" + hjrc_Result.timeStamp + "\",\"package\":\"" + hjrc_Result.package + "\",\"paySign\":\"" + hjrc_Result.paySign + "\",\"signType\":\"" + hjrc_Result.signType + "\"}";
|
||||
Mtxfw.Utility.Common.WriteHtml("/weixin/xapiajaxstrstart2.txt", data);
|
||||
b = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
b = false;
|
||||
data = "{\"status\":0,\"msg\":\"" + hr.data.resp_desc + "\"}";
|
||||
|
||||
Mtxfw.Utility.Common.WriteHtml("/weixin/xapiajaxstrstart3.txt", data);
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
b = false;
|
||||
data = "{\"status\":0,\"msg\":\"" + hr.data.resp_desc + "\"}";
|
||||
|
||||
Mtxfw.Utility.Common.WriteHtml("/weixin/xapiajaxstrstart3.txt", data);
|
||||
// ========================================
|
||||
// 微信小程序支付 - 创建JSAPI支付订单
|
||||
// 功能: 调用微信统一下单接口,获取小程序调起支付所需的参数
|
||||
// ========================================
|
||||
try
|
||||
{
|
||||
// 步骤1: 创建微信小程序支付类实例
|
||||
// config参数包含: appid、商户号、密钥等配置信息
|
||||
Mtxfw.Utility.MiniProgramPay miniPay = new Mtxfw.Utility.MiniProgramPay(config);
|
||||
|
||||
// 步骤2: 金额转换
|
||||
// PayZSubTotal单位为元,需转换为分(乘以100)
|
||||
// 微信支付接口要求金额单位为分
|
||||
int totalFee = (int)(PayZSubTotal * 100);
|
||||
|
||||
// 步骤3: 设置支付回调通知地址
|
||||
// 支付成功后微信会向此地址发送异步通知
|
||||
string notifyUrl = config.webUrl + "/pay/wxpaynotify_url.aspx";
|
||||
|
||||
// 步骤4: 调用创建JSAPI支付订单接口
|
||||
// openid: 用户在小程序中的唯一标识
|
||||
// PayID: 商户订单号,需保证唯一性
|
||||
// totalFee: 订单金额,单位: 分
|
||||
// body: 商品描述
|
||||
// notifyUrl: 支付结果通知回调地址
|
||||
Mtxfw.Utility.MiniProgramPayResult payResult = miniPay.CreateJsApiOrder(openid, PayID, totalFee, body, "", notifyUrl);
|
||||
|
||||
// 步骤5: 处理支付订单创建结果
|
||||
if (payResult.Success)
|
||||
{
|
||||
// 创建成功,设置小程序调起支付所需的参数
|
||||
// timeStamp: 时间戳,自1970年以来的秒数
|
||||
// nonceStr: 随机字符串,用于签名计算
|
||||
// package: 订单详情,格式为prepay_id=xxx
|
||||
// paySign: 签名,用于安全校验
|
||||
// signType: 签名类型,固定为MD5
|
||||
timestamp = payResult.TimeStamp;
|
||||
nonceStr = payResult.NonceStr;
|
||||
package = payResult.Package;
|
||||
paySign = payResult.PaySign;
|
||||
signType = payResult.SignType;
|
||||
|
||||
// 记录成功日志,便于问题排查
|
||||
Mtxfw.Utility.Common.WriteHtml("/weixin/miniProgramPaySuccess.txt", miniPay.GetPayResultJson(payResult));
|
||||
}
|
||||
else
|
||||
{
|
||||
// 创建失败,返回错误信息给前端
|
||||
b = false;
|
||||
data = "{\"status\":0,\"msg\":\"" + payResult.Message + "\"}";
|
||||
|
||||
// 记录失败日志,包含错误码和错误描述
|
||||
Mtxfw.Utility.Common.WriteHtml("/weixin/miniProgramPayError.txt", miniPay.GetPayResultJson(payResult));
|
||||
}
|
||||
}
|
||||
catch (Exception exPay)
|
||||
{
|
||||
// 异常处理: 捕获并记录异常信息
|
||||
b = false;
|
||||
data = "{\"status\":0,\"msg\":\"支付创建失败\"}";
|
||||
|
||||
// 记录异常详情到日志文件
|
||||
Mtxfw.Utility.Common.WriteHtml("/weixin/miniProgramPayException.txt", exPay.ToString());
|
||||
|
||||
// 记录错误日志到数据库,便于后续排查
|
||||
Model.User_Errlog errLog = new Model.User_Errlog();
|
||||
errLog.DLID = 0;
|
||||
errLog.ErrType = "微信小程序支付异常";
|
||||
errLog.addtime = DateTime.Now;
|
||||
errLog.ErrBody = openid + "|" + PayID + "|" + PayZSubTotal; // 记录关键参数
|
||||
errLog.ErrBody2 = exPay.ToString(); // 记录异常详情
|
||||
new DAL.User_Errlog().Add(errLog);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 使用HuifuPaymentService
|
||||
/* Mtxfw.Utility.Common.WriteHtml("/weixin/xapiajaxstrstart.txt", "3");
|
||||
string sys_id = config.hfpaysys_id;
|
||||
|
||||
2
修改说明.txt
2
修改说明.txt
@@ -20,7 +20,7 @@ log4net: log4net 是 Apache 软件基金会旗下著名组件 log4j 的 .NET
|
||||
4. 管理员菜单权限更新脚本:
|
||||
|
||||
update Adminjs set
|
||||
js='VIP会员列表 | 提货点列表 | 实名认证列表 | 推荐图谱查询 | 修改推荐人 | 删除会员 | 注册新会员 | 修改余额 | 修改会员资料 | 会员级别升级记录 | 高级管理功能 | 资讯管理 | 企业介绍 | 发图素材 | 健康知识 | 修改隐私政策 | 修改用户服务协议 | 客服信息管理 | 滚动图片管理 | 微信菜单管理 | 操作教程 | 视频管理 | 奖金详情 | 删除奖金明细 | 充值管理 | 提现管理 | 导出数据 | 盛世丰花优选商品列表 | 热卖推荐商品列表 | 订单列表 | 商品分类管理 | 运费设置 | 管理员列表 | 角色管理 | 系统设置 | 数据管理 | 登录日志 | 操作日志 | 修改兑换券 | 兑换商城商品列表 | 门店管理 | 联盟部管理 |'
|
||||
js='VIP会员列表 | 提货点列表 | 实名认证列表 | 推荐图谱查询 | 修改推荐人 | 删除会员 | 注册新会员 | 修改余额 | 修改会员资料 | 会员级别升级记录 | 高级管理功能 | 资讯管理 | 企业介绍 | 发图素材 | 健康知识 | 修改隐私政策 | 修改用户服务协议 | 客服信息管理 | 滚动图片管理 | 微信菜单管理 | 操作教程 | 视频管理 | 奖金详情 | 删除奖金明细 | 充值管理 | 提现管理 | 导出数据 | 盛世丰花优选商品列表 | 热卖推荐商品列表 | 订单列表 | 商品分类管理 | 运费设置 | 管理员列表 | 角色管理 | 系统设置 | 数据管理 | 登录日志 | 操作日志 | 修改兑换券 | 兑换商城商品列表 | 联盟部管理 |'
|
||||
where id=1
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user