public async Task <ActionResult> CreatePay(Payment payment) { String payendpoint = configuration.GetValue <string>("SecurePay:Endpoint") + configuration.GetValue <string>("SecurePay:WeChatAPI"); String merchantcode = configuration.GetValue <string>("SecurePay:MerchantCode"); var authValue = new AuthenticationHeaderValue("Bearer", payment.AccessToken); var IdempotencyKey = Guid.NewGuid(); client.DefaultRequestHeaders.Authorization = authValue; client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var wechatModel = new WeChatModel { merchantCode = merchantcode, ip = Request.HttpContext.Connection.RemoteIpAddress.ToString(), amount = payment.Amount, orderId = IdempotencyKey.ToString(), orderDescription = payment.Description, paymentChannel = "InBrowser", redirectUrls = new RedirectUrls { successUrl = payment.SuccessUrl } }; string json = JsonConvert.SerializeObject(wechatModel); var stringContent = new StringContent(json, Encoding.UTF8, "application/json"); var response = await client.PostAsync(payendpoint, stringContent); var responseString = await response.Content.ReadAsStringAsync(); return(Ok(responseString)); }
//列表 public ActionResult List() { WeChatModel model = new WeChatModel(); model.WeChatList = WeChats.GetWeChatList(); SiteUtils.SetAdminRefererCookie(Url.Action("list")); return(View(model)); }
/// <summary> /// 上传图片 /// </summary> /// <returns></returns> public ActionResult UploadImage(string serverIds) { var ImageList = new List <object>(); //返回的图片的Url List <string> serverIdArray = serverIds.Split(',').ToList(); foreach (var serverId in serverIdArray) { WeChatModel model = new WeChatModel(); model.sAppId = sAppId; model.sAppSecret = sAppSecret; string sRequestUrl = "https://api.weixin.qq.com/cgi-bin/media/get?access_token={0}&media_id={1}"; sRequestUrl = string.Format(sRequestUrl, model.sAccessToken, serverId); /************************************微信服务器上下载图片************************************/ HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(sRequestUrl); webRequest.ProtocolVersion = HttpVersion.Version10; webRequest.Timeout = 3000; webRequest.Method = WebRequestMethods.Http.Get; webRequest.Headers.Add("Accept-Encoding", "gzip, deflate"); HttpWebResponse webResponse = (System.Net.HttpWebResponse)webRequest.GetResponse(); Stream streamReceive = webResponse.GetResponseStream(); //响应流转内存流 MemoryStream memoryStream = StreamToMemoryStream(streamReceive); string baseStr = Convert.ToBase64String(memoryStream.ToArray()); //获取图片后缀名 string format = string.Empty; Image image = Bitmap.FromStream(memoryStream); var ImageFormats = GetImageFormats(); foreach (var pair in ImageFormats) { if (pair.Value.Guid == image.RawFormat.Guid) { format = pair.Key; break; } } //上传图片到服务器 Parameter.method = "UploadPicture"; JArray ImageArray = new JArray(); ImageArray.Add(new JObject(new JProperty("picName", GuidHelper.GuidTo16String() + format), new JProperty("picCoding", baseStr.Replace("+", "%2b")))); string sBody = string.Format("moduleName=保修单&picCodingList={0}", ImageArray.ToString()); var response = HttpHelper.HttpPost(Parameter, sBody); if (response.Code == 1) { string PicPath = Convert.ToString(JsonHelper.Deserialize <JArray>(JsonHelper.ToJsonString(response.Data))[0]["PicPath"]); string sUrl = ImageUrl + PicPath; ImageList.Add(sUrl); } } result.success = true; result.data = ImageList; return(Json(result)); }
public ActionResult Add(WeChatModel model) { WeChatInfo weChatInfo = new WeChatInfo(); if (ModelState.IsValid) { weChatInfo.name = model.name; weChatInfo.appid = model.appid; weChatInfo.secret = model.secret; WeChats.CreateWeChat(weChatInfo); return(PromptView("公众号添加成功")); } return(View(model)); }
//更新 public ActionResult Edit(int id = -1) { WeChatInfo weChatInfo = WeChats.GetWeChatById(id); if (weChatInfo == null) { return(PromptView("公众号不存在")); } WeChatModel model = new WeChatModel(); model.id = weChatInfo.id; model.name = weChatInfo.name; model.appid = weChatInfo.appid; model.secret = weChatInfo.secret; return(View(model)); }
public ActionResult Edit(WeChatModel model, int id) { WeChatInfo weChatInfo = WeChats.GetWeChatById(id); if (weChatInfo == null) { return(PromptView("公众号不存在")); } if (ModelState.IsValid) { weChatInfo.name = model.name; weChatInfo.appid = model.appid; weChatInfo.secret = model.secret; weChatInfo.id = model.id; WeChats.UpdateWeChat(weChatInfo); AddAdminOperateLog("修改公众号", "修改公众号,公众号ID为:" + id); return(PromptView("公众号修改成功")); } return(View(model)); }
public ActionResult Add() { WeChatModel model = new WeChatModel(); return(View(model)); }