Convenient payment payment (2)

In the previous article, I talked about generating a QR code for payment. The next step is WeChat payment. The program is almost written, just run with the merchant number to be tested by Weifutong. They gave it, but it didn’t work. I was puzzled. Later, I asked them in detail whether the WeChat Wap channel was still available. They said that the WeChat official had closed the payment channel permission for pure mobile browsers. At that time, I wanted to close it. Why Wei Fortis officially displayed the WeChat Wap document. What should I do? . . If this doesn’t work, change the course. You can also get the Openid of the user you want by authorization. Then study it again. The prerequisite for authorization is that the WeChat public account appid and secret development password must be required. With this, everything is easy to do, hahahaha share picture

General process:

Scan the code to display the individual merchant login page, enter the account password, enter the main page, the upper column displays the account number + individual merchant name, click on personal information to see the detailed information. Pending payment records, self-service payment, payment records. The key point is to talk about the records to be paid. The WeChat used here is scanned and entered, so only the WeChat payment channel is displayed. (Judging whether it is a WeChat browser or an Alipay browser can be distinguished)

p>

Share a picture Share Image

Share a picture Share pictures

share picture

 //Configure the authorization address and just jump here, the first time the code does not need to be assigned, rurl will jump after authorization Address

public ActionResult Index(string code, string rurl)
{
bool flag = HJFController.config == null< span style="color: #000000;">;
if (flag)
{
this.Reload();
}
//WeChat official account, development password, official account webpage authorization address , Put in the configuration
string appid = HJFController.config.appid;
string secret = HJFController.config.secret;
string redirecturl = HJFController.config.redirecturl;

if (!string.IsNullOrWhiteSpace(rurl))
Session[
"xxxxxxxxxx"] = rurl;
bool flag2 = string.IsNullOrEmpty(code);
ActionResult result;
if (flag2)
{
string url = string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri ={1}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect", appid, HttpUtility .UrlEncode(redirecturl));
result
= this.Redirect(url);
}
else
{
WebClient webClient
= new WebClient();
webClient.Encoding
= Encoding.UTF8;
string address = string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret ={1}&code={2}&grant_type=authorization_code", appid, secret, code);
string input = webClient.DownloadString(address);
JavaScriptSerializer javaScriptSerializer
= new JavaScriptSerializer();
Dictionary
<string, string> dictionary = javaScriptSerializer. Deserializestring, string>>(input);
string text;
bool flag3 = !dictionary.TryGetValue("< span style="color: #800000;">access_token", out text);
if (flag3)
{
result
= base.Content("Error");
}
else
{
string arg = dictionary["openid"];
Session[
"WeiXinOpenId"] = arg;
string x = string.Empty;
var rr = Session["xxxxxxxxxx"];
if (rr != null)
x
= System.Web.HttpUtility.UrlEncode(rr.ToString());
result
= this.Redirect(string.Format( "{0}?openid={1}&url={2}", HJFController.config.finalurl, arg, x));
}
}
return result;
}

View Code

So you can get it. Tell the customer that you need them They don’t provide the WeChat official account. It’s a bumpy road. It’s more like a bank. If you don’t give it, it’s understandable. But if you don’t give it to me, you won’t let the payment succeed. I finally negotiated and let me go. I asked them to return me a user Openid. I said that I still do so many things, so I can still learn something. 1. Check the order before payment 2. WeChat payment must have parameters

 Share picture

 /// 

/// Pay from the mobile phone terminal
///

/// Order number
/// Total amount
/// Additional information
/// Pay the user’s openid
/// Return address after payment is completed
/// Whether to pay in original ecology
///
public Result getAppPayUrl(string ddh, string allMoney, string attach, string sub_openid, string callback_url, bool f)
{
var ipAddress = PayHelper.WeiXinHZ.PayHZ.GetHostAddress();
RequestHandler reqHandler
= new RequestHandler(null);
reqHandler.setParameter(
"service", "pay.weixin.jspay span>");//Interface type: pay.weixin.jspay
reqHandler.setParameter("mch_id", MerchantId);//Required item, merchant number, Assigned by VFT
if (!string.IsNullOrEmpty(Sub_appid))
{
reqHandler.setParameter(
"sub_appid", Sub_appid);//WeChat Sub_appid< /span>
}
reqHandler.setParameter(
"notify_url", notify_url);//notification address, Required. The URL to receive notifications from Weifutong must be an absolute path, within 255 characters; this URL must be accessible from the Internet
reqHandler.setParameter("callback_url", callback_url);
reqHandler.setParameter(
"out_trade_no", ddh);//merchant order number
reqHandler.setParameter("body", ddh);//Product description
reqHandler.setParameter("attach", attach);//The additional information stores the payment method code, Convenient write-back library
reqHandler.setParameter("total_fee", allMoney);//Total amount
reqHandler.setParameter("mch_create_ip", ipAddress);//Terminal IP
if (!string.IsNullOrWhiteSpace(MerchantId) && MerchantId != < span style="color: #800000;">"
7551000001" )//Test merchant number
reqHandler.setParameter("sub_openid", sub_openid);//user openid

//You don’t need to pass the user’s openid to use the test merchant number; switch to official You need to obtain openid for your merchant account,
//Add the sub_openid field to the request parameters, and put the obtained The openid value is passed to sub_openid.
//Before switching to the official merchant account to pass the sub_openid parameter, you must Provide the official merchant account and the official account (service account) appid configured by us,
//If there is no configuration, it will report sub_appid and sub_openid not match Error, which prevents the interface from being called normally
if (isRsaKey())
{
reqHandler.setParameter(
"sign_type", "RSA_1_256");//signature type,
}
else
{
reqHandler.setParameter(
"sign_type", "MD5");//signature type, Value: MD5 Default: MD5
}
// reqHandler.setParameter("service", "pay.weixin .native");//Interface type: pay.weixin.native pay.alipay .native
// reqHandler.setParameter("nonce_str", Utils.random( )); // has been assigned afterwards
if (f)
reqHandler.setParameter(
"is_raw", "1");//Whether it is original
var strdata = Exe(reqHandler);
if (isRsaKey())
MerchantKey
= MerchantPublicKey; //If it is rsa, the returned result needs to be passed Public key
var result = new TokenResult(strdata, MerchantKey);
if (result.Success)
{
if (f)
{
return new Result {Success = true, Message = result.pay_info };
}
else
{
var msg = string.Format("https://pay.swiftpass.cn/pay/jspay?token_id={0}&showwxtitle=1 span>", result.token_id);
return new Result {Success = true, Message = msg };
}
}
return new Result {Success = false, Message = result.message ?? (result.err_code + result.err_msg) };
}

View Code

share picture

  //Configure the authorization address and jump here, the first time the code does not need to be assigned, rurl will let you jump to the address after authorization

public ActionResult Index(string code, string rurl)
{
bool flag = HJFController.config == null< span style="color: #000000;">;
if (flag)
{
this.Reload();
}
//WeChat official account, development password, official account webpage authorization address , Put in the configuration
string appid = HJFController.config.appid;
string secret = HJFController.config.secret;
string redirecturl = HJFController.config.redirecturl;

if (!string.IsNullOrWhiteSpace(rurl))
Session[
"xxxxxxxxxx"] = rurl;
bool flag2 = string.IsNullOrEmpty(code);
ActionResult result;
if (flag2)
{
string url = string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri ={1}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect", appid, HttpUtility .UrlEncode(redirecturl));
result
= this.Redirect(url);
}
else
{
WebClient webClient
= new WebClient();
webClient.Encoding
= Encoding.UTF8;
string address = string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret ={1}&code={2}&grant_type=authorization_code", appid, secret, code);
string input = webClient.DownloadString(address);
JavaScriptSerializer javaScriptSerializer
= new JavaScriptSerializer();
Dictionary
<string, string> dictionary = javaScriptSerializer. Deserializestring, string>>(input);
string text;
bool flag3 = !dictionary.TryGetValue("< span style="color: #800000;">access_token", out text);
if (flag3)
{
result
= base.Content("Error");
}
else
{
string arg = dictionary["openid"];
Session[
"WeiXinOpenId"] = arg;
string x = string.Empty;
var rr = Session["xxxxxxxxxx"];
if (rr != null)
x
= System.Web.HttpUtility.UrlEncode(rr.ToString());
result
= this.Redirect(string.Format( "{0}?openid={1}&url={2}", HJFController.config.finalurl, arg, x));
}
}
return result;
}

View Code

 //Configure the authorization address and skip to here, the first time the code does not need to be assigned, rurl will let you jump to the address after authorization

public ActionResult Index(string code, string rurl)
{
bool flag = HJFController.config == null< span style="color: #000000;">;
if (flag)
{
this.Reload();
}
//WeChat official account, development password, official account webpage authorization address , Put in the configuration
string appid = HJFController.config.appid;
string secret = HJFController.config.secret;
string redirecturl = HJFController.config.redirecturl;

if (!string.IsNullOrWhiteSpace(rurl))
Session[
"xxxxxxxxxx"] = rurl;
bool flag2 = string.IsNullOrEmpty(code);
ActionResult result;
if (flag2)
{
string url = string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri ={1}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect", appid, HttpUtility .UrlEncode(redirecturl));
result
= this.Redirect(url);
}
else
{
WebClient webClient
= new WebClient();
webClient.Encoding
= Encoding.UTF8;
string address = string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code", appid, secret, code);
string input = webClient.DownloadString(address);
JavaScriptSerializer javaScriptSerializer
= new JavaScriptSerializer();
Dictionary
<string, string> dictionary = javaScriptSerializer.Deserializestring, string>>(input);
string text;
bool flag3 = !dictionary.TryGetValue("access_token", out text);
if (flag3)
{
result
= base.Content("Error");
}
else
{
string arg = dictionary["openid"];
Session[
"WeiXinOpenId"] = arg;
string x = string.Empty;
var rr = Session["xxxxxxxxxx"];
if (rr != null)
x
= System.Web.HttpUtility.UrlEncode(rr.ToString());
result
= this.Redirect(string.Format("{0}?openid={1}&url={2}", HJFController.config.finalurl, arg, x));
}
}
return result;
}

分享图片

   /// 

/// 从手机端公从号支付
///

/// 订单号
/// 总金额
/// 附加信息
/// 支付用户的openid
/// 支付完成后的返回地址
/// 是否原生态支付
///
public Result getAppPayUrl(string ddh, string allMoney, string attach, string sub_openid, string callback_url, bool f)
{
var ipAddress = PayHelper.WeiXinHZ.PayHZ.GetHostAddress();
RequestHandler reqHandler
= new RequestHandler(null);
reqHandler.setParameter(
"service", "pay.weixin.jspay");//接口类型:pay.weixin.jspay
reqHandler.setParameter("mch_id", MerchantId);//必填项,商户号,由威富通分配
if (!string.IsNullOrEmpty(Sub_appid))
{
reqHandler.setParameter(
"sub_appid", Sub_appid);//微信Sub_appid
}
reqHandler.setParameter(
"notify_url", notify_url);//通知地址,必填项,接收威富通通知的URL,需给绝对路径,255字符内;此URL要保证外网能访问
reqHandler.setParameter("callback_url", callback_url);
reqHandler.setParameter(
"out_trade_no", ddh);//商户订单号
reqHandler.setParameter("body", ddh);//商品描述
reqHandler.setParameter("attach", attach);//附加信息 存放支付方式编码,方便回写库
reqHandler.setParameter("total_fee", allMoney);//总金额
reqHandler.setParameter("mch_create_ip", ipAddress);//终端IP
if (!string.IsNullOrWhiteSpace(MerchantId) && MerchantId != "7551000001")//测试商户号
reqHandler.setParameter("sub_openid", sub_openid);//用户openid

//使用测试商户号不需要传用户openid;切换正式的商户号需获取openid,
//在请求参数里增加sub_openid字段,并把获取的openid值传给sub_openid。
//在切换成正式商户号传sub_openid参数前,需提供 正式商户号和公众号(服务号)appid由我方配置,
//如果没有配置的话,会报sub_appid and sub_openid not match错误,导 致无法正常调用接口
if (isRsaKey())
{
reqHandler.setParameter(
"sign_type", "RSA_1_256");//签名类型,
}
else
{
reqHandler.setParameter(
"sign_type", "MD5");//签名类型,取值:MD5 默认:MD5
}
// reqHandler.setParameter("service", "pay.weixin.native");//接口类型:pay.weixin.native pay.alipay.native
// reqHandler.setParameter("nonce_str", Utils.random()); //后已经赋值了
if (f)
reqHandler.setParameter(
"is_raw", "1");//是否原生态
var strdata = Exe(reqHandler);
if (isRsaKey())
MerchantKey
= MerchantPublicKey; //如果是rsa 则返回结果 需要传递 公钥
var result = new TokenResult(strdata, MerchantKey);
if (result.Success)
{
if (f)
{
return new Result { Success = true, Message = result.pay_info };
}
else
{
var msg = string.Format("https://pay.swiftpass.cn/pay/jspay?token_id={0}&showwxtitle=1", result.token_id);
return new Result { Success = true, Message = msg };
}
}
return new Result { Success = false, Message = result.message ?? (result.err_code + result.err_msg) };
}

View Code

   /// 

/// 从手机端公从号支付
///

/// 订单号
/// 总金额
/// 附加信息
/// 支付用户的openid
/// 支付完成后的返回地址
/// 是否原生态支付
///
public Result getAppPayUrl(string ddh, string allMoney, string attach, string sub_openid, string callback_url, bool f)
{
var ipAddress = PayHelper.WeiXinHZ.PayHZ.GetHostAddress();
RequestHandler reqHandler
= new RequestHandler(null);
reqHandler.setParameter(
"service", "pay.weixin.jspay");//接口类型:pay.weixin.jspay
reqHandler.setParameter("mch_id", MerchantId);//必填项,商户号,由威富通分配
if (!string.IsNullOrEmpty(Sub_appid))
{
reqHandler.setParameter(
"sub_appid", Sub_appid);//微信Sub_appid
}
reqHandler.setParameter(
"notify_url", notify_url);//通知地址,必填项,接收威富通通知的URL,需给绝对路径,255字符内;此URL要保证外网能访问
reqHandler.setParameter("callback_url", callback_url);
reqHandler.setParameter(
"out_trade_no", ddh);//商户订单号
reqHandler.setParameter("body", ddh);//商品描述
reqHandler.setParameter("attach", attach);//附加信息 存放支付方式编码,方便回写库
reqHandler.setParameter("total_fee", allMoney);//总金额
reqHandler.setParameter("mch_create_ip", ipAddress);//终端IP
if (!string.IsNullOrWhiteSpace(MerchantId) && MerchantId != "7551000001")//测试商户号
reqHandler.setParameter("sub_openid", sub_openid);//用户openid

//使用测试商户号不需要传用户openid;切换正式的商户号需获取openid,
//在请求参数里增加sub_openid字段,并把获取的openid值传给sub_openid。
//在切换成正式商户号传sub_openid参数前,需提供 正式商户号和公众号(服务号)appid由我方配置,
//如果没有配置的话,会报sub_appid and sub_openid not match错误,导 致无法正常调用接口
if (isRsaKey())
{
reqHandler.setParameter(
"sign_type", "RSA_1_256");//签名类型,
}
else
{
reqHandler.setParameter(
"sign_type", "MD5");//签名类型,取值:MD5 默认:MD5
}
// reqHandler.setParameter("service", "pay.weixin.native");//接口类型:pay.weixin.native pay.alipay.native
// reqHandler.setParameter("nonce_str", Utils.random()); //后已经赋值了
if (f)
reqHandler.setParameter(
"is_raw", "1");//是否原生态
var strdata = Exe(reqHandler);
if (isRsaKey())
MerchantKey
= MerchantPublicKey; //如果是rsa 则返回结果 需要传递 公钥
var result = new TokenResult(strdata, MerchantKey);
if (result.Success)
{
if (f)
{
return new Result { Success = true, Message = result.pay_info };
}
else
{
var msg = string.Format("https://pay.swiftpass.cn/pay/jspay?token_id={0}&showwxtitle=1", result.token_id);
return new Result { Success = true, Message = msg };
}
}
return new Result { Success = false, Message = result.message ?? (result.err_code + result.err_msg) };
}

Leave a Comment

Your email address will not be published.