微信电子发票怎么接入?微信电子发票接入流程

作者:微微号 点击:56 发布时间:2021-12-02

  微信电子发票怎么接入?微信电子发票接入流程,随着微信电子发票的推出,越来越多的公司开始使用起了微信电子发票,但我们要知道微信电子发票使用起来并不简单,首先在使用之前,我们得接入微信电子发票。下面小编就给大家讲下微信电子发票怎么接入?微信电子发票接入流程。

  一、微信电子发票接流程图

  电子发票流程涉及用户、商户、报销方、发票平台和公众平台五个角色。

  对于自建发票平台的商户,发票平台即为商户自身的开票系统,承担着制作发票卡券、将发

  票卡券插入用户卡包以及报销状态更新的关键作用。

  二、微信电子发票接入步骤及页面

  步骤1:检查是否微信打开

  步骤2:检查微信版本是否高于或者等于6.0.2版本

  //"Mozilla/5.0(iphone;CPU iphone OS 5_1_1 like Mac OS X)    

  //AppleWebKit / 534.46(KHTML, like Geocko)Mobile / 9B206 MicroMessenger/ 6.0.2 "

  //其中6.0.2为用户安装的微信版本号。商户可以判定版本号是否高于或者等于6.0.2。

  步骤3:检查发票是否真实存在

  步骤4:获取微信token

  /// <summary>        ///获取微信token        /// </summary>        /// <returns></returns>        public static string GetToken()        {            string CGIBaseUrl = GlobalConfig.Settings["WechartBaseUrl"];            string AppId = GlobalConfig.Settings["EfpgjAppId"];            string security = GlobalConfig.Settings["EfpgjSecurity"];            ObjectCache oCache = MemoryCache.Default;            string fileContents = oCache["wechart_token"] as string;            if (fileContents == null)            {                var url = string.Format("{0}/token?grant_type=client_credential&appid={1}&secret={2}",                CGIBaseUrl + "/cgi-bin", AppId, security);                using (WebClient client = new WebClient())                {                    client.Encoding = Encoding.UTF8;                    string data = client.DownloadString(url);                    var result = JObject.Parse(data);                    if (result["access_token"] != null && result["access_token"].Value<string>() != string.Empty)                    {                        CacheItemPolicy policy = new CacheItemPolicy();                        policy.AbsoluteExpiration = DateTime.Now.AddMinutes(120);//取得或设定值,这个值会指定是否应该在指定期间过后清除                        fileContents = result["access_token"].Value<string>();                        oCache.Set("wechart_token", fileContents, policy);                    }                }            }            return fileContents;        }   

  步骤5:获取发票平台 s_pappid

  步骤6:获取发票 ticket

  /// <summary>        /// 获取临时Ticket        /// </summary>        /// <param name="token"></param>        /// <returns></returns>        public static string GetTicket(string token)        {            ObjectCache oCache = MemoryCache.Default;            string fileContents = oCache["wechart_ticket"] as string;            if (fileContents == null)            {                string CGIBaseUrl = GlobalConfig.Settings["WechartBaseUrl"];                var url = string.Format("{0}/cgi-bin/ticket/getticket?access_token={1}&type=wx_card",                    CGIBaseUrl, token);                var data = string.Empty;                var arg = new                {                    access_token = token                };                var paramStr = JsonConvert.SerializeObject(arg);                using (var client = new WebClient())                {                    client.Encoding = Encoding.UTF8;                    data = client.UploadString(url, paramStr);                }                var result = JObject.Parse(data);                CacheItemPolicy policy = new CacheItemPolicy();                policy.AbsoluteExpiration = DateTime.Now.AddMinutes(120);//取得或设定值,这个值会指定是否应该在指定期间过后清除                fileContents = result["ticket"].Value<string>();                oCache.Set("wechart_ticket", fileContents, policy);            }            return fileContents;        }

  步骤7:获取授权页链接URL

  /// <summary>        /// 获取授权页链接        /// </summary>        /// <param name="CGIBaseUrl"></param>        /// <param name="token"></param>        /// <returns></returns>        public static string GetAuthUrl(string token, EInvoice invoice, int flags)        {            var spid = CheckToken(token);            try            {                string CGIBaseUrl = GlobalConfig.Settings["WechartBaseUrl"];                var url = string.Format("{0}/card/invoice/getauthurl?access_token={1}",                        CGIBaseUrl, token);                var data = string.Empty;                var arg = new                {                    s_pappid = spid,                    order_id = invoice.SwiftNumber,                    money = invoice.SummaryAmount * 100,                    timestamp = ConvertDateTimeInt(DateTime.Now),                    source = "web",                    redirect_url = GlobalConfig.Settings["WechartEIUrl"] + "/#!/wechartCardReturn/" + invoice.Id+"/"+invoice.CustomerName + "/" + flags,                    //redirect_url = "http://eiapp.chinacloudsites.cn" + "/#!/testInsertcardCpt/" + SwiftNumber,                    ticket = GetTicket(token),                    type = 2,//授权类型, 0:开票授权, 1:填写字段开票授权, 2:领票授权                };                var paramStr = JsonConvert.SerializeObject(arg);                using (var client = new WebClient())                {                    client.Encoding = Encoding.UTF8;                    data = client.UploadString(url, paramStr);                }                var result = JObject.Parse(data);                if (result["auth_url"] != null && result["auth_url"].Value<string>() != string.Empty)                {                    return result["auth_url"].Value<string>();                }                else                    return data;            }            catch (Exception ex)            {                return spid + "/" + token + "/" + ex.Message;            }        }

  步骤8:步骤7接口字段:授权成功后跳转页面,此页面中进行创建卡券-将电子发票插入用户卡包中操作

  以上就是小编为大家整理的关于微信微信电子发票怎么接入?微信电子发票接入流程的全部内容。不知道大家有没有学会,如果你想了解更多更精彩的内容请持续关注微信素材网。

  

我们是一家专业提供公众号交易、公众号迁移、公众号增粉、公众号买卖交易的平台,如果您有这方面的需求,。有任何疑问,可以 【立即咨询】 我们平台的客服或者添加微信号 【19180581726】 。此文章来源于网络,如有侵权,请联系删除

标签:

资金保障

提供买卖双方资金担保交易
更放心

法律保障

交易签订具有法律效益合同
提供法律支持

急速退款

专属资金通道,快速拿到
钱款

全资公司

全资控股公司,大平台交易
有保障

服务优质

3500+专业团队,为您提供24
小时一对一贴心服务