first, access to micro-letter payment Mchid,key,appid,appsecret four payment key values.
Micro-credit payment merchant platform Https://pay.weixin.qq.com/index.php/core/home/login?return_url=%2F
1. Login to the micro-credit payment merchant platform to obtain the merchant number (Mchid),
2. In the "Account Center" column "API Security" column set API key (key)
Micro-Credit public number: https://mp.weixin.qq.com/
1. Sign in to micro-trust get Application ID (APPID) and Application key (Appsecret) in the "Basic Configuration" column
2. In the "Interface Permissions" column "Web account" binding official payment of the domain name (such as: xxxx.net, do not http: and "/" slash)
3. In the "micro-credit Payment" column "Development Configuration" inside the set up public payment authorization directory (such as: xxxx.net/wechatweb/)
Second, add Wxpayapi to the production project, in the Config.cs file to modify the obtained Mchid,key,appid,appsecret four key values and Notify_url values (Notify_url is the payment authorization directory) and build a Wechatweb controller in the MVC project, with logical code in it. and pass the micro-letter Jsapi to pay the required parameters. The code example is as follows:
Background Action Code
<summary>///access to micro-credit payment///</summary>///<returns></returns> [httpget] Public
Virtual ActionResult Index () {Jsapipay jsapipay = new Jsapipay ();
Ostudent model = NULL;
try {//Invoke the "Web page authorization Get user Information" interface to get the user's OpenID and Access_token Jsapipay.getopenidandaccesstoken ();
Obtain the micro-credit payer public id Jsapipay.openid = Jsapipay.openid; String id = request["id"]; If you want to get the value of the page passed over, you need to modify the code in the Getopenidandaccesstoken () method, plus Request.Url.Query get the parameter model = Ostudentsiteservice.getbykey ( ID).
AppendData as Ostudent; if (model!= null) {Jsapipay.total_fee = 1;//Test Order Amount (1 for cent, official amount to *100) jsapipay.order_id = model.order_id;// Order Number (custom order number)}//JSAPI payment preprocessing//Call Unified order, get the next single result wxpaydata Unifiedorderresult = Jsapipay.getunifiedorderr
Esult (); Obtain a micro-letter browser from the data successfully returned from the unified list JSAPI the required parameters for the payment of the variable var wxjsapiparam = Jsapipay.getjsapiparameters (); Gets the JSON format string viewbag.wxjsapiparam = Wxjsapiparam; Front page JS calls Log.debug (this. GetType().
ToString (), "Wxjsapiparam:" + Wxjsapiparam); The catch (Exception ex) {Response.Write (ex). Message + "," + ex.
Source);
Response.End ();
return View (model); //Modify payment method [HttpPost] public virtual Jsonresult Paymethod () {Ajaxjsonresult ajax = new Ajaxjsonresult () {E rr = true, msg = string.
Empty, timeout = 3};
String id = request.form["id"];
String paymethod = request.form["Paymethod"]; var model = (Project.Core.Models.Model.OStudent) ostudentsiteservice.getbykey (ID).
AppendData; Model.paymethod = Paymethod;
Payment method Operationresult result = Ostudentsiteservice.modify (model); if (result.
Resulttype = = operationresulttype.success) {Ajax.err = false;
Ajax.msg = "successful operation";
Return Json (AJAX); ///<summary>///Modify payment status///</summary>///<param name= "UserID" ></param>///<re turns></returns> [HttpPost] public virtual string editpaystatus (Guid UserID) {string msg= "Error"; var model = Ostudentsiteservice.getbykey (UserID).
AppendData as Ostudent; Model. Status = (int) x.project.site.models.enum.paystatus.success;
Payment success Operationresult result = Ostudentsiteservice.modify (model); if (result.
Resulttype = = operationresulttype.success) {msg = "OK";
return msg; Front index.chtml View page JS code <script type= "Text/javascript" > var _wxjsapiparam = eval (' (@Html. Raw (VIEWBAG.WXJS
Apiparam));
function Callpay () {//Select payment method var Paymethod = $ ("input[name= ' Paymethod ']:checked"). Val (); if (Paymethod = = "" | |
Paymethod = = null) {layer.msg ("Please select payment method", function () {}) return false;
} $.ajax ({type: "POST", DataType: "JSON", url: ' @Url. Action ("Paymethod", "Wechatweb") ', data: {
Paymethod:paymethod, ID: ' @Model. Id '}, success:function (data) {//Express Modify Payment Method success if (!data.err) { 1 means the micro-letter payment, then call the micro-letter Payment if (Paymethod = = "1") {if (typeof WEIXINJSBRidge = = "undefined") {if (Document.addeventlistener) {document.addeventlistener (' Weixinjsbridgeready '),
Jsapicall, false);
else if (document.attachevent) {document.attachevent (' Weixinjsbridgeready ', jsapicall);
Document.attachevent (' Onweixinjsbridgeready ', jsapicall);
} else {jsapicall (); } else if (Paymethod = "2") {Layer.alert (' Congratulations, operation successful! '), function () {window.location.href = "@Url . Action (MVC). Default.index ()) ";
After the successful operation of the Jump page});
} else {layer.msg ("operation Failed", function () {}) return false;
}
}
}); //Call micro-letter JS API payment function Jsapicall () {weixinjsbridge.invoke (' getbrandwcpayrequest ', _wxjsapiparam, function (r)
ES) {if (res.err_msg = = "Get_brand_wcpay_request:cancel") {layer.msg ("Canceled Payment", function () {});
return false;
else if (res.err_msg = "Get_brand_wcpay_request:ok") {//Payment successfulAjax $.ajax ({type: "POST", DataType: "text", url: ' @Url. Action ("Editpaystatus", "Wechatweb") ', data: {userID: ' @Model. ID '}, error:function (Request) {layer.msg ("Server Error!
", function () {});
return false; }, Success:function (data) {window.location.href = "@Url. Action (MVC). Default.index ()) "; After the successful payment of the page to jump}});
Ajax End}});
} </script>
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.