微信JSApi支付~微信支付代理模式的实现(原创)

时间:2020-12-07 13:26:45

返回目录

起因(大叔原创)

对于微信支付来说,你的发起者需要配置对应的域名来获取code(获取用户信息接口),而这意味着,你的多个项目(域名不同)不能同时使用一个公众号,这是一件很操蛋的事,对于我们开发人员来说,当然不能接受,我们需要一种代理模式,代我们实现多个项目使用一个公众号(一个支付的域名),这是必须的,说做就做。(支付发起者可以多个域名,最多三个,就是我们说的权限目录那块)

原理

开始-》

第三方网站重定向在代理服务器-》

代理服务器跳到微信服务器拿code-》

返回 code到代理服务器-》

代理服务器再发跳到微信服务器拿 openid和token-》

返回openid和token到代理服务器-》

当openid不为空时跳回第三方网站服务器-》

由第三方服务的支付完成最后的付款过程-》

结果

思维图像

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAu4AAAGSCAIAAAAzd9O6AAAgAElEQVR4nO2dX4wc1b3neQhKlJtNokj7ivpto5UiRZuX3JfsPqx0Xzfrh+yucpOrK0KiDZlmPP4bOxhCcAKJMAFjINjAjD2e8X9sY48Jxo7BeP6PZ8ZOwDK2wQyenj+2LxcsNh6h3odJRk3VOb86VV19Tp06n4++GnVXV5/6Vdu/U5853TNzRx0AAADAW+5wXQAAAABAdlAZAAAA8BhUBgAAADwGlQEAAACPQWUAAADAY1AZAAAA8BhUBgAAADwGlQEAAACPQWUAAADAY1AZAAAA8BhUBgAAADwGlQEAAACPQWUAAADAY1AZAAAA8BhUBgAAADwGlQEAAACPQWUAAADAY1AZAAAA8BhUBgAAADwGlQEAAACPQWUAAADAY1AZAAAA8BhUBgAAADwGlQEAAACPQWUAAADAY1AZAAAA8BhUBgAAADwGlQEAAACPQWUAAADAY1AZAAAA8BhUBgAAADwGlQEAAACPQWUAAADAY1AZAAAA8JgUKjM1f+vw0PtrOkfXdI5+75FTyzaeJIQQEkgWJ//tJy5dqX3UumuSd5w/9T+HDn2DGOZC/48+/fT/5f6vYKoye06/+5MtA2t2TDzWd+mZE1e7B2t7R2b3jRJCCCl/eoZ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degMoQQQrIHlQHnoDKEEEKyB5UB50gq0zM0s39sjhBCCNEFlQHnoDKEEEKyB5UB5ySozL6xOUIIIUSXXagMuAaVIYQQkj2oDDgHlSGEEJI9qAw4R1KZnUO1vaOzhBBCiC67hmdQGXALKkMIISR7UBlwToLK7BmdJYQQQnTpRWXANaLKDNb2jMwSQgghuqAy4BxJZboHa7tHZgkhhBBdelAZcA0qQwghJHtQGXAOKkMIISR7UBlwToLK7BqeIYQQQnTpGUJlwDGoDCGEkOxBZcA5qAwhhJDsQWXAOZLK7Bis9Q7PEEIIIbrsRGXANaLKDNR6hmYIIYQQXboHURlwDCpDCCEke1AZcA4qQwghJHtQGXCOpDLbB6Z3DtYIIYQQXboHa6gMuAWVIYQQkj2oDDgHlSGEEJI9qAw4R1KZroHp7sEaIYQQosuOAVQGHKNVmbufOLP19SnnTUIIIaTI2T4wjcqAW7Qq07Ft+Mk/XtkxWCOEEEJ02XZ66oebTtu8bgFE0KrMU0fffnDvW9tdNwkhhJDiZqD2uyPv3N89bvO6BRBBqzJjl65Xt4509U+7bxVCCCGFTNfA9Krt46+MfmDzugUQQasy9Xr9/u7x3x55Z/tAbfvANCGEENKYroHpJ199d/m24dsLn1q7aAHEkVTm5sd/vWdz/9Y3PnDeMIQQQoqWF968du+zQ1dqH1m7YgEokVSmXq+/fr5W3Tqy9fQHXQPThBBCyGJeePPayq6zLw1ctXOtAhBIUJl6vX58/No9m/t/e+Sdrv5pQgghgafzzLWnXnuv7blhPAYKQrLK1Ov1mx//9f7u8ZVdZ39z+OKL/dOdi/+bCSGEhJHFOf/FM9ceP3Z5zY6Je58dvDD1YauvTwCGGKnMIicmph/aNbFs40lCCCFhpmPb8OGh9/mcLxSKFCoDAAAAUDRQGQAAAPAYVAYAAAA8BpUBAAAAj0FlAAAAwGNQGQAAAPCY/w+bjUTVtbJglwAAAABJRU5ErkJggg==" alt="" />

实现

#region 代理模式
/// <summary>
/// 微信支付
/// 从代理服务器获取openID
/// 注意:代理服务器与本服务器需要有预定,双方要告诉对应的URL地址,用来进行二次跳转
/// </summary>
/// <returns></returns>
public ActionResult Weixin()
{
string openId = Request.QueryString["openId"];
if (string.IsNullOrWhiteSpace(openId))
{
//第一次加载页面,跳转到代理服务器获openid
Logger.LoggerFactory.Instance.Logger_Info("openid为空");
Response.Redirect("http://m.xxx.cn/order/GetOpenId"); }
else
{
//由代理服务器跳回来后,得到本用户的openId
Logger.LoggerFactory.Instance.Logger_Info("从m158拿到openid:" + openId);
ViewBag.openId = openId;
}
return View();
} /// <summary>
/// 微信支付的代理服务
/// </summary>
/// <returns></returns>
public void WeixinProxy()
{
string openId = JsApiImplement.GetOpenId();//获取当前openId
string bussinessUrl = "";//业务网站支付地址
if (!string.IsNullOrWhiteSpace(openId))
Redirect(bussinessUrl + "?openId=" + openId);
}
/// <summary>
/// 获取支付JSON串
/// </summary>
/// <param name="orderId"></param>
/// <param name="money"></param>
/// <param name="openId"></param>
/// <returns></returns>
public string GetPayJson(string orderId, int money, string openId)
{
try
{
Logger.LoggerFactory.Instance.Logger_Info("发送订单号=" + orderId + ",openID=" + openId);
//JsApiImplement.GetOpenId();加到主页面上
return JsApiImplement.Send(money, orderId, openId); }
catch (Exception ex)
{ Logger.LoggerFactory.Instance.Logger_Error(ex);
return "出错了";
} }
#endregion

在测试过程中出现过一些问题,然后通过日志分析解决了,感觉在oauth权限过程中,页面重定向成为了唯一的方式,以后这种方式我们应该在自己的项目中多多使用!

感谢这个坑很多的微信!

没有你的坑,我们也不会学到这么多知识!

返回目录