当前位置:网站首页>Example: use C # Net to teach you how to develop wechat official account (21) -- using wechat to pay online collection: H5 method
Example: use C # Net to teach you how to develop wechat official account (21) -- using wechat to pay online collection: H5 method
2022-06-26 00:43:00 【Chaos scar】
On the line 、 Offline sales , You can use wechat to pay conveniently , There are many ways to collect money through wechat official account , Here's the picture :

Let's talk about it today H5 Scenario payment , Open it with mobile browser H5 The way , The most common promotion is SMS built-in links , This scenario requires calling wechat app, Then start wechat payment and subsequent processes .
One 、 Operation demo
Use whatever you like to scan the code app Scan the QR code below , After opening, copy the link to the mobile browser opening page .


Two 、 Wechat payment configuration
In the first of this series 18 piece ((2 Bar message ) example : use C#.NET Teach you to do WeChat official account development (18)-- Use wechat payment to send red envelopes to fans _ The blog of scar in troubled times -CSDN Blog ) There was an introduction to , In addition to the basic configuration , The following configurations are key :

3、 ... and 、H5 Scenario payment demo source code
The source code of the front page is as follows :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="H5Test.aspx.cs" Inherits="Jjlm.H5Test" %>
<!DOCTYPE html>
<html>
<head runat="server">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
<title> Wechat payment H5 Collection test </title>
</head>
<style>
img{
width: 100%;
display: block;
}
body{
margin:0;padding:0;
background-repeat: no-repeat;
background-size: 100% 100%;
}
.line{
display: flex;justify-content:space-between;height: 40px;margin: 0 20px;
}
.boline{
border-bottom: 1px solid #ddd;
}
.ti{
font-size: 18px;
line-height: 40px;
}
.text{
font-size: 16px;
line-height: 40px;
}
</style>
<body>
<div style="width: 100%;background:#555;color:#fff;font-size:20px;height: 40px;line-height: 40px;text-align: center;">
Cashier
</div>
<form id="form1" runat="server">
<div>
<div style="margin-top:10px;background: #fff;">
<div class="line boline">
<span class="ti"> The order number :</span>
<asp:Label runat="server" id="lbBillNo" Text="" Visible="true" class="text" />
</div>
<div class="line boline">
<span class="ti"> product :</span>
<asp:Label runat="server" id="lbProductName" Text="" Visible="true" class="text" />
</div>
<div class="line boline">
<span class="ti"> The number : </span>
<asp:Label runat="server" id="lbProductNum" Text="" Visible="true" class="text" />
</div>
<div class="line">
<span class="ti"> Pay the amount :</span>
<asp:Label runat="server" id="lbTotalFee" Text="" Visible="true" class="text" style="color: crimson;" />
</div>
</div>
<div style="margin: 10px auto;">
<img src="img/wxzf.jpg" alt="" style="width: 100%;">
</div>
<div style="margin: 10px auto;width: 90%;height: 40px;background: #20a91d;border-radius:10px;text-align: center;" runat="server" id="divBtn">
<asp:Button ID="submit" runat="server" Text=" Pay now " Style="background: #20a91d;border-width:0px;color: #fff;line-height: 35px;font-size: 20px;outline:0px;-webkit-appearance: none;" OnClick="btnCallPayClick"/>
</div>
</br>
<asp:Label runat="server" id="lbProductId" Text="" Visible="false" class="text" />
<asp:Label runat="server" id="lbUrl" Text="" Visible="true" class="text" />
</div>
</form>
</body>
</html>The back-end source code is as follows :
using System;
using System.Web;
using System.Web.UI;
using System.Data;
using System.Data.SqlClient;
using QinMing.Config;
using QinMing.WeixinPayCollect;
namespace Jjlm
{
public partial class H5Test : System.Web.UI.Page
{
public static string wxJsApiParam {get;set;} //H5 Tune up JS API Parameters
protected void Page_Load(object sender, EventArgs e)
{
lbProductId.Text = "202102040001";
lbProductName.Text = " Wechat payment H5 test ";
lbBillNo.Text = DateTime.Now.ToString("yyyyMMddHHmmssms"); //
lbProductNum.Text = "1";
lbTotalFee.Text = "0.01";
}
protected void btnCallPayClick(object sender, EventArgs e)
{
string fee = (Convert.ToDouble(lbTotalFee.Text)*100).ToString(); /// Wechat units are divided into
string out_trade_no = lbBillNo.Text;
if (lbProductName.Text != null)
{
// If relevant parameters are passed , Then adjust the unified ordering interface , Obtain the entry parameters of subsequent related interfaces
H5Pay h5Pay = new H5Pay();
string scip = GetWebClientIp();// Get client reality IP
string url = h5Pay.GetPayUrl(scip,fee,out_trade_no,lbProductId.Text,lbProductName.Text);
lbUrl.Text = url;
Response.Redirect(url, false);// Jump to the middle page of wechat payment
}
else
{
Log.showlog("zhifu_callpay"," Page missing parameter , Please go back and try again ");
}
}
public string GetWebClientIp()
{
string userIP = "";
try
{
if (System.Web.HttpContext.Current == null
|| System.Web.HttpContext.Current.Request == null
|| System.Web.HttpContext.Current.Request.ServerVariables == null)
return "";
string CustomerIP = "";
//CDN It is taken after acceleration IP simone 090805
CustomerIP = System.Web.HttpContext.Current.Request.Headers["Cdn-Src-Ip"];
if (!string.IsNullOrEmpty(CustomerIP))
{
return CustomerIP;
}
CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (!String.IsNullOrEmpty(CustomerIP))
{
return CustomerIP;
}
if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
{
CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (CustomerIP == null)
CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
else
{
CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
if (string.Compare(CustomerIP, "unknown", true) == 0)
return System.Web.HttpContext.Current.Request.UserHostAddress;
return CustomerIP;
}
catch { }
return userIP;
}
}
}Four 、 Collection source code
The classes used in the above demonstration code are the same as those in the previous article , The source code has been given in the last article .
And the table used to store the collection records is also given in the previous article , There is only one field marked with different payment sources .
5、 ... and 、 After collection, the collection record status is updated
The content introduced in the previous article is the same , The code will no longer be posted repeatedly .
The front-end code :WeixinPayRecvResultNotify.aspx
Back end code :WeixinPayRecvResultNotify.aspx.cs
边栏推荐
- Types of feeder and how to work
- Openresty chapter 01 introduction and installation configuration
- Qt优秀开源项目之九:qTox
- 毕业季 | 在不断探索中拟合最好的自己
- How ASA configures port mapping and pat
- DPVS fullnat mode kept
- Analyze the five root causes of product development failure
- Is camkiia the same as gcamp6f?
- 【超能云终端创领先机】如何在48小时内交付一座方舱医院?
- idea设置mapper映射文件的模板
猜你喜欢

SSL unresponsive in postman test

1-10vmware builds customized network architecture

Idea view unit test coverage

Leetcode 513. Find the value in the lower left corner of the tree

Regular expression introduction and some syntax
![[advanced ROS] Lecture 1 Introduction to common APIs](/img/25/85e8c55605f5cc999a8e85f0a05f93.jpg)
[advanced ROS] Lecture 1 Introduction to common APIs

idea设置mapper映射文件的模板

CaMKIIa和GCaMP6f是一樣的嘛?

mtb13_Perform extract_blend_Super{Candidate(PrimaryAlternate)_Unique(可NULL过滤_Foreign_index_granulari

leetcode.14 --- 最长公共前缀
随机推荐
Methods to realize asynchrony
Anti shake and throttling
使用VS2022編譯Telegram桌面端(tdesktop)
Servlet response download file
Understanding of prototypes and prototype chains
Compiler Telegram Desktop end (tdesktop) en utilisant vs2022
Explain the synchronize keyword
How to design the product roadmap?
Idea view unit test coverage
Mining pit record of modified field information in Dameng database
Compile the telegraph desktop side (tdesktop) using vs2022
Idea set the template of mapper mapping file
Why is it best to use equals for integer comparisons
When installing PSU /usr/bin/ld:warning: -z lazload ignore
深圳台电:联合国的“沟通”之道
Causes and solutions to the phenomenon of PCBA monument in SMT patch processing
QT excellent open source project 9: qtox
EBS r12.2.0 to r12.2.6
【超能云终端创领先机】如何在48小时内交付一座方舱医院?
yolov5 提速多GPU训练显存低的问题