Winform开发框架集成微信、支付宝在线支付功能
Winform开发框架集成微信、支付宝在线支付功能
Winform支付页面
创建支付订单
C# 全选
private void btn_GenerateOrder_Click(object sender, EventArgs e)
{
//请求模型
Req_GenerateOrder requestData = new Req_GenerateOrder()
{
Site = "1688",
AliID = "",
Phone = _license.Mobile,
Code = GetPriceCode(),
PayType = (sender as Control).Tag.ToString()
};
//请求接口
var data = ServerDataHelper.DoApiOP(requestData, "PayGenerateOrder");
if (data.Code == 0)
{
var v = data.ConvertToObject<Res_GenerateOrder>();
this.CurrentOrderID = v.OrderID;
pictureBox2.Image = CreateQRCode(v.URL, Properties.Resources.logo2);
btn_QueryOrder.Enabled = true;
btn_QueryOrder.Image = Properties.Resources.支付宝支付完成;
StartLoop();
}
else
{
frmMsg.ShowError(data.Message);
}
}
调用后台WebApi接口
C# 全选
public static ModelResponse DoApiOP(object queryOrData, string operationName)
{
string url = GetURL() + "api/do/post";
string data = ConvertData(queryOrData);
ModelRequestAction M = new ModelRequestAction
{
Action = 888091688,
ClientData = "",
Operation = operationName,
Timestamp = DateTime.Now.ToString("yyyyMMddHHmmss"),//时间戳
ApiKey = PrivateKeys.ApiKey,
Data = data,
DataIsEncrypted = false,//不需要加密
};
//Sign数字签名
M.Sign = Core.CryptoHelper.ToMD5(M.ApiKey + M.Data + PrivateKeys.SecretKey + M.Timestamp);
string json = JsonConvert.SerializeObject(M, JsonSettings.Current);
string result = WebApiTools.Post(url, json);
ModelResponse response = JsonConvert.DeserializeObject<ModelResponse>(result, JsonSettings.Current);
return response;
}
CSFramework.WebApi开发框架
https://www.cscode.net/archive/webapi/1630590361.html
生成支付二维码(中间带Logo)
C#代码 - QRCodeEncoder类
C# 全选
/// <summary>
/// 生成二维码(中间带LOGO)
/// </summary>
/// <param name="absoluteSave">保存的绝对路径</param>
/// <param name="qrdata">二维码内容:要附加的内容</param>
///<param name="absoluteSave">保存的绝对路径</param>
/// <returns></returns>
Image CreateQRCode(string qrdata, Image logo)
{
try
{
QRCodeEncoder encoder = new QRCodeEncoder();
encoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;//编码方式(注意:BYTE能支持中文,ALPHA_NUMERIC扫描出来的都是数字)
encoder.QRCodeScale = 5;//大小(值越大生成的二维码图片像素越高)
encoder.QRCodeVersion = 0;//版本(注意:设置为0主要是防止编码的字符串太长时发生错误)
encoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H;//错误效验、错误更正(有4个等级)
encoder.QRCodeBackgroundColor = Color.White;
encoder.QRCodeForegroundColor = Color.Black;
System.Drawing.Image image = encoder.Encode(qrdata, Encoding.UTF8);
Graphics g = Graphics.FromImage(image);
int width1 = image.Width / 4;
int height1 = image.Height / 4;
int x = image.Width / 2 - width1 / 2;
int y = image.Height / 2 - height1 / 2;
g.FillRectangle(new SolidBrush(Color.White), x, y, width1, height1);
Bitmap copyImage = new Bitmap(logo, width1 - image.Width / 40, height1 - image.Height / 40);
g.DrawImage(copyImage, x + image.Width / 40 / 2, y + image.Height / 40 / 2);
copyImage.Dispose();
g.Dispose();
return image;
}
catch (Exception e)
{
throw e;
//一些操作
}
}
二维码图片效果
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网