.NET Core之微信支付之公众号、H5支付篇

论坛 期权论坛     
选择匿名的用户   2021-5-30 02:02   263   0
<div class="blogpost-body" id="cnblogs_post_body">
<h1>前言</h1>
<p>本篇主要记录微信支付中公众号及H5支付全过程。</p>
<h2>准备篇</h2>
<p>公众号或者服务号(并开通微信支付功能)、商户平台中开通JSAPI支付、H5支付。</p>
<h2>配置篇</h2>
<p>公众号或者服务号中 -------开发-------开发者工具---------web开发者工具-------绑定为开发者</p>
<p>公众号或者服务号中 -------公众号设置--------功能设置   :填写业务域名、JS安全域名、网页授权域名 示例:pay.one.com</p>
<p>商户平台中--------产品中心-------开发配置------JSAPI支付授权目录填写:http://pay.one.com/    http://pay.one.com/WeChatPay/PubPay/-----H5支付填写:pay.one.com</p>
<p><img alt="" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-9229549d6f1872bb9d40f48d6be3aa24.png"></p>
<p> </p>
<p><img alt="" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-e347b1b95ab92dfa2676d48513a491a0.png"></p>
<p> </p>
<p><img alt="" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-b217e9562a16c04d9f76d63fa3fe540b.png"></p>
<p> </p>
<p>若对配置还有疑问,可参考官方文档:</p>
<p><a href="https://mp.weixin.qq.com/wiki?t&#61;resource/res_main&amp;id&#61;mp1421140842">https://mp.weixin.qq.com/wiki?t&#61;resource/res_main&amp;id&#61;mp1421140842</a></p>
<p><a href="https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter&#61;7_7&amp;index&#61;6">https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter&#61;7_7&amp;index&#61;6</a></p>
<h2>开发篇</h2>
<h3>JSAPI支付</h3>
<p>本Demo是基于Payment 的SDK开发。具体详情可参考:<a href="https://github.com/Essensoft/Payment">https://github.com/Essensoft/Payment</a></p>
<p>首先 使用Nuget安装payment:</p>
<p>Install-Package  :Essensoft.AspNetCore.Payment.WeChatPay -Version 2.3.2</p>
<p>建一个Model: WeChatPayPubPayViewModel</p>
<p> </p>
<div class="cnblogs_code">
  <pre class="blockcode"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span><span style="color:#000000;"> WeChatPayPubPayViewModel
    {
        [Required]
        [Display(Name </span>&#61; <span style="color:#800000;">&#34;</span><span style="color:#800000;">out_trade_no</span><span style="color:#800000;">&#34;</span><span style="color:#000000;">)]
        </span><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> OutTradeNo { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span><span style="color:#000000;">; }

        [Required]
        [Display(Name </span>&#61; <span style="color:#800000;">&#34;</span><span style="color:#800000;">body</span><span style="color:#800000;">&#34;</span><span style="color:#000000;">)]
        </span><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> Body { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span><span style="color:#000000;">; }

        [Required]
        [Display(Name </span>&#61; <span style="color:#800000;">&#34;</span><span style="color:#800000;">total_fee</span><span style="color:#800000;">&#34;</span><span style="color:#000000;">)]
        </span><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">int</span> TotalFee { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span><span style="color:#000000;">; }

        [Required]
        [Display(Name </span>&#61; <span style="color:#800000;">&#34;</span><span style="color:#800000;">spbill_create_ip</span><span style="color:#800000;">&#34;</span><span style="color:#000000;">)]
        </span><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> SpbillCreateIp { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span><span style="color:#000000;">; }

        [Required]
        [Display(Name </span>&#61; <span style="color:#800000;">&#34;</span><span style="color:#800000;">notify_url</span><span style="color:#800000;">&#34;</span><span style="color:#000000;">)]
        </span><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> NotifyUrl { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span><span style="color:#000000;">; }

        [Required]
        [Display(Name </span>&#61; <span style="color:#800000;">&#34;</span><span style="color:#800000;">trade_type</span><span style="color:#800000;">&#34;</span><span style="color:#000000;">)]
        </span><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> TradeType { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span><span style="color:#000000;">; }

        [Required]
        [Display(Name </span>&#61; <span style="color:#800000;">&#34;</span><span style="color:#800000;">openid</span><span style="color:#800000;">&#34;</span><span style="color:#000000;">)]
        </span><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> OpenId { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span><span style="color:#000000;">; }
    }</span></pre>
</div>
<p>WeChatPayController:</p>
<div class="cnblogs_code">
  <pre class="bloc
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP