private void ShowInfo() { var weixin = GetWeiXinCode(); lblWeixinName.Text = weixin.WxName; lblAppid.Text = weixin.AppId; var wxpayBll = new PaymentService(); var model = wxpayBll.GetModelByAppId(weixin.Id); if (model == null || model.Id == 0) { //新增记录 } else { //修改 hidId.Value = model.Id.ToString(); this.txtmch_id.Text = model.MchId; this.txtpaykey.Text = model.Paykey; this.txtcertInfoPath.Text = model.CertInfoPath; this.txtcerInfoPwd.Text = model.CerInfoPwd; } var propertyBll = new PropertyService(new PropertyRepository()); var propertyEntity = propertyBll.GetModelByIName(weixin.Id, MXEnums.WXPropertyKeyName.OpenOauth.ToString()); if (propertyEntity != null) { radOpenOAuth.SelectedValue = propertyEntity.iContent; hidOpenOauthId.ID = propertyEntity.Id.ToString(); } }
//保存 protected void btnSubmit_Click(object sender, EventArgs e) { var wxpayBll = new PaymentService(); int id = MyCommFun.Obj2Int(hidId.Value, 0); var wxpayModel = new PaymentInfo(); var weixin = GetWeiXinCode(); if (id == 0) { //新增 wxpayModel.AppId = weixin.Id; wxpayModel.CreateDate = DateTime.Now; } else { //修改 wxpayModel = wxpayBll.GetModel(id); } wxpayModel.MchId = txtmch_id.Text.Trim(); wxpayModel.Paykey = txtpaykey.Text.Trim(); wxpayModel.CertInfoPath = txtcertInfoPath.Text.Trim(); wxpayModel.CerInfoPwd = txtcerInfoPwd.Text.Trim(); bool ret = false; if (id == 0) { wxpayModel.CreateDate = DateTime.Now; int retNum = wxpayBll.Add(wxpayModel); if (retNum > 0) { ret = true; } } else { ret = wxpayBll.Update(wxpayModel); } //OpenOAuth开启 var propertyBll = new PropertyService(new PropertyRepository()); string pValue = radOpenOAuth.SelectedItem.Value; propertyBll.AddProperty(weixin.Id, MXEnums.WXPropertyKeyName.OpenOauth.ToString(), pValue); if (ret) { JscriptMsg("修改信息成功!", "baseSetting.aspx", "Success"); } else { JscriptMsg("修改信息成功!", "", "Error"); return; } }
/// <summary> /// //更新access_token值 /// </summary> /// <param name="_id"></param> /// <param name="AppId"></param> /// <param name="AppSecret"></param> private void UpdateAccess_Token(int _id, string AppId, string AppSecret) { try { var pBll = new PropertyService(new PropertyRepository()); if (!pBll.ExistsWid(_id)) { return; } string newToken = ""; try { var result = OneGulp.WeChat.MP.CommonAPIs.CommonApi.GetToken(AppId, AppSecret); newToken = result.access_token; } catch (Exception ex) { JscriptMsg("AppId或者AppSecret填写错误!", "", "Error"); } finally { //更新到数据库里 var wxProperty = pBll.GetModelList("iName='access_token' and wid=" + _id)[0]; wxProperty.iContent = newToken; wxProperty.createDate = DateTime.Now; pBll.Update(wxProperty); } } catch (Exception ex) { } }