1.登录微信公众平台:
1.1设置密钥
1.2设置服务器需要访问的IP
1.3设置服务器配置(上篇文章写到)
1.4查看APPID
2.登录商户平台
2.1申请和微信公众平台进行绑定
2.2域名回调地址
2.3查看API密钥(注意是V2版本还是V3版本)
2.4查看商户号
3.代码编写
3.1进行统一下单接口 (代码如下)
3.2返回的参数给前端,由前端进行调起微信支付
3.3后端设置回调地址和接口,进行设置订单的状态。
var tenPayData = new TenPayRequestData(
entity.AppId,
entity.MchNo,
"微信支付通知",
outTradeNo,
payMoney,
ConfigurationManager.AppSettings["IP"],
notifyUrl,
(TenPayV3Type)Enum.Parse(typeof(TenPayV3Type), payType, true),
openID,
entity.MchKey,
WeixinHelper.Tools.GetNonceStr(),
attach,
string.Empty
);
var unifiedordeResult = WeixinHelper.Pay.Unifiedorder(tenPayData);
public TenPayRequestData(string appId, string mchId, string body, string outTradeNo, decimal totalFee, string spbillCreateIp, string notifyUrl, TenPayV3Type tradeType, string openid, string key, string nonceStr, string attach, string product_id)
{
AppId = appId;
MchId = mchId;
NonceStr = nonceStr;
Body = body ?? "Senparc TenpayV3";
OutTradeNo = outTradeNo;
TotalFee = totalFee;
SpbillCreateIP = spbillCreateIp;
NotifyUrl = notifyUrl;
TradeType = tradeType;
OpenId = openid;
Key = key;
Attach = attach;
Product_id = product_id;
#region 设置RequestHandler
//创建支付应答对象
PackageRequestHandler = new RequestHandler(null);
//初始化
PackageRequestHandler.Init();
thi