Пример #1
0
        /// <summary>
        /// 绑定微信到商家收退款地址
        /// </summary>
        /// <param name="weixinMsg"></param>
        /// <param name="sceneid"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        private string BindingByShopShipper(RequestMessageEventBase weixinMsg, string sceneid, SceneModel model)
        {
            try
            {
                var key         = CacheKeyCollection.SceneReturn(sceneid);
                var sceneResult = Core.Cache.Get <Mall.DTO.WeiXinInfo>(key);
                if (sceneResult == null)
                {
                    var siteSetting = SiteSettingApplication.SiteSettings;
                    if (!(string.IsNullOrWhiteSpace(siteSetting.WeixinAppId) || string.IsNullOrWhiteSpace(siteSetting.WeixinAppSecret)))
                    {
                        string token    = AccessTokenContainer.TryGetAccessToken(siteSetting.WeixinAppId, siteSetting.WeixinAppSecret);
                        var    userinfo = Senparc.Weixin.MP.CommonAPIs.CommonApi.GetUserInfo(token, weixinMsg.FromUserName);
                        string sex      = "未知";
                        switch (userinfo.sex)
                        {
                        case 1: sex = "男"; break;

                        case 2: sex = "女"; break;
                        }
                        var WeiXinInfo = new Mall.DTO.WeiXinInfo
                        {
                            OpenId     = weixinMsg.FromUserName,
                            NickName   = userinfo.nickname,
                            city       = userinfo.city,
                            province   = userinfo.province,
                            sex        = sex,
                            headimgurl = userinfo.headimgurl
                        };
                        if (Core.Cache.Get <WeiXinInfo>(key) != null)
                        {
                            Core.Cache.Remove(key);
                        }
                        Core.Cache.Insert(key, WeiXinInfo, 300);
                    }
                    else
                    {
                        Core.Log.Error("微信事件回调:未设置公众号配置参数!");
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("Binding:" + ex.Message);
            }
            return(string.Empty);
        }
Пример #2
0
 public JsonResult GetStateCompleted(bool state, Mall.DTO.WeiXinInfo model)
 {
     return(Json(new { success = state, data = model }));
 }