In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how the version of MVC paid by Wechat official account is. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
First, get the four payment key values of WeChat Pay MCHID,KEY,APPID,APPSecret.
WeChat Pay merchant platform https://pay.weixin.qq.com/index.php/core/home/login?return_url=%2F
1. Log in to WeChat Pay's merchant platform to get the merchant number (MCHID)
two。 Set the API key (KEY) in the "API Security" column under "account Center".
Official account of Wechat: https://mp.weixin.qq.com/
1. Log in to Wechat to get the application ID (APPID) and application key (APPSecret) in the "basic configuration" column.
two。 Under the "Interface permissions" column, "Web account" binds the domain name that is officially paid (for example: * × × .net, no http: and "/" slash)
3. Set up the payment authorization directory for public payment in "Development configuration" under "WeChat Pay" column (for example: × × × .net / WeChatWeb/)
Second, add WxPayAPI to the production project, modify the four key values of MCHID,KEY,APPID,APPSecret and the NOTIFY_ URL value in the Config.cs file (NOTIFY_URL is the payment authorization directory), and build a WeChatWeb controller in the MVC project with logic code. And pass the parameters required for Wechat jsapi payment. The code example is as follows:
Background Action code
/ obtain relevant information about WeChat Pay / [HttpGet] public virtual ActionResult Index () {JsApiPay jsApiPay = new JsApiPay (); OStudent model = null; try {/ / call the API [Web Authorization to obtain user Information] to obtain the user's openid and access_token jsApiPay.GetOpenidAndAccessToken (); / / get the public id jsApiPay.openid of Wechat payers = jsApiPay.openid String ID = Request ["ID"]; / / if you want to get the value passed by the page, you need to modify the code in the GetOpenidAndAccessToken () method and add the Request.Url.Query acquisition parameter model = OStudentSiteService.GetByKey (id). AppendData as OStudent; if (model! = null) {jsApiPay.total_fee = 1 model / test order amount (1 means points, official amount is * 100) jsApiPay.Order_ID = model.order_ID / / order number (self-defined order number)} / / JSAPI payment preprocessing / / call unified order issuance to get the order result WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult (); / / obtain the parameter var wxJsApiParam = jsApiPay.GetJsApiParameters () needed by Wechat browser to call up jsapi payment from the data returned by unified order issuance; / / get the json format string ViewBag.wxJsApiParam = wxJsApiParam / / the foreground page js calls Log.Debug (this.GetType (). ToString (), "wxJsApiParam:" + wxJsApiParam);} 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 () {err = 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);} / modify payment status / [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.SuccessEnum.PayStatus.Successsuccessful payment OperationResult result = OStudentSiteService.Modify (model); if (result.ResultType = = OperationResultType.Success) {msg = "ok";} return msg;} foreground Index.chtml view page JS code var _ wxJsApiParam = eval ('(@ Html.Raw (ViewBag.wxJsApiParam)') Function callpay () {/ / Select payment method var payMethod = $("input [name = 'PayMethod']: checked"). Val (); if (payMethod = "" | payMethod = = null) {layer.msg ("Please choose payment method", function () {}) return false } $.ajax ({type: "POST", dataType: "JSON", url:'@ Url.Action ("PayMethod", "WeChatWeb")', data: {payMethod: payMethod, id:'@ Model.ID'}, success: function (data) {/ / indicates successful modification of payment method if (! data.err) {/ / 1 means WeChat Pay Then call WeChat Pay 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, successful operation!', function () {_ window.location.href = "@ Url.Action (MVC.Default.Index ())"; / / Jump page after successful operation});}} else {layer.msg ("operation failed", function () {}) return false Call Wechat JS api to pay function jsApiCall () {WeixinJSBridge.invoke ('getBrandWCPayRequest', _ wxJsApiParam, function (res) {if (res.err_msg = = "get_brand_wcpay_request:cancel") {layer.msg ("cancelled", function () {}); return false } else if (res.err_msg = = "get_brand_wcpay_request:ok") {/ / payment succeeded / / ajax $.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 ())"; / / pages redirected after successful payment}}); / / ajax end}}) } about Wechat official account pay MVC version is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.