public ServiceResult <WxMP_JssdkConfigOutput> config(WxMP_JssdkConfigInput input) { var result = _mp_jssdk.GetConfig(input); Response.StatusCode = result.code; return(result); }
/// <summary> /// 获取jssdk配置 /// </summary> /// <param name="mid"></param> /// <param name="url"></param> /// <returns></returns> public ServiceResult <WxMP_JssdkConfigOutput> GetConfig(WxMP_JssdkConfigInput input) { try { input.CheckNull(nameof(WxMP_JssdkConfigInput)); input.guid.CheckEmpty(nameof(input.guid)); input.url.CheckEmpty(nameof(input.url)); var config = new WxMP_JssdkConfigOutput(); //时间戳 config.time_stamp = WxContext.Common.GenerateTimeStamp(); //随机字符 config.nonce_str = WxContext.Common.GenerateNonceStr(); //获取微信配置 var wechatConfig = _middleDB.WechatConfig.Select(s => new { s.Id, s.Guid, s.AppId }).FirstOrDefault(w => w.Guid == input.guid); config.app_id = wechatConfig.AppId; //token var token = _configService.GetAccessToken(new WxMP_AuthorizeAccessTokenInput { wid = wechatConfig.Id }); if (token.code != StatusCodes.Status200OK) { return(ServiceResult <WxMP_JssdkConfigOutput> .Failed(token.code, token.msg)); } //jsapi_ticket var ticket = GetJsapiTicket(new WxMP_JssdkJsapiTicketInput { guid = wechatConfig.Guid, access_token = token.data.access_token }); //signature config.signature = WxContext.Common.GenerateSignature(config.time_stamp, config.nonce_str, ticket.data.jsapi_ticket, input.url); return(ServiceResult <WxMP_JssdkConfigOutput> .Success(config)); } catch (Exception ex) { return(ServiceResult <WxMP_JssdkConfigOutput> .Exception(ex.Message)); } }