程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> 關於.NET >> 微信開發 :WeixinPayInfoCollection尚未注冊Mch 問題解決,微信開發解決方案

微信開發 :WeixinPayInfoCollection尚未注冊Mch 問題解決,微信開發解決方案

編輯:關於.NET

微信開發 :WeixinPayInfoCollection尚未注冊Mch 問題解決,微信開發解決方案


在使用開源項目 SENPARC.WEIXIN SDK 調用微信支付接口的時候出現了WeixinPayInfoCollection尚未注冊Mch,這個問題。

 

最後地解決方案是:

我這個傻逼忘了在全局Global初始化TenPayV3InfoCollection

只要在Global 添加以下代碼

//提供微信支付信息
var tenPayV3_MchId = System.Configuration.ConfigurationManager.AppSettings["TenPayV3_MchId"];
var tenPayV3_Key = System.Configuration.ConfigurationManager.AppSettings["TenPayV3_Key"];
var tenPayV3_AppId = System.Configuration.ConfigurationManager.AppSettings["TenPayV3_AppId"];
var tenPayV3_AppSecret = System.Configuration.ConfigurationManager.AppSettings["TenPayV3_AppSecret"];
var tenPayV3_TenpayNotify = System.Configuration.ConfigurationManager.AppSettings["TenPayV3_TenpayNotify"];

var tenPayV3Info = new TenPayV3Info(tenPayV3_AppId, tenPayV3_AppSecret, tenPayV3_MchId, tenPayV3_Key,
tenPayV3_TenpayNotify);
TenPayV3InfoCollection.Register(tenPayV3Info);

 

代碼示例:

        private static TenPayV3Info _tenPayV3Info;
        /// <summary>
        /// v3 微信 支付模式屬性
        /// </summary>
        public static TenPayV3Info TenPayV3Info
        {
            get
            {
                if (_tenPayV3Info == null)
                {
                    _tenPayV3Info =TenPayV3InfoCollection.Data[System.Configuration.ConfigurationManager.AppSettings["TenPayV3_MchId"]];
                }
                return _tenPayV3Info;
            }
        } 

        protected void Application_Start(object sender, EventArgs e)
        {
            RegisterWeixinPay();
        }

        //提供微信支付信息
        var tenPayV3_MchId = System.Configuration.ConfigurationManager.AppSettings["TenPayV3_MchId"];
        var tenPayV3_Key = System.Configuration.ConfigurationManager.AppSettings["TenPayV3_Key"];
        var tenPayV3_AppId = System.Configuration.ConfigurationManager.AppSettings["TenPayV3_AppId"];
        var tenPayV3_AppSecret = System.Configuration.ConfigurationManager.AppSettings["TenPayV3_AppSecret"];
        var tenPayV3_TenpayNotify = System.Configuration.ConfigurationManager.AppSettings["TenPayV3_TenpayNotify"];

        var tenPayV3Info = new TenPayV3Info(tenPayV3_AppId, tenPayV3_AppSecret, tenPayV3_MchId, tenPayV3_Key,tenPayV3_TenpayNotify);
        TenPayV3InfoCollection.Register(tenPayV3Info);

webconfig 配置

    <!-- 微信支付V3 -->
    <add key="TenPayV3_MchId" value="TenPayV3_MchId"/>
    <add key="TenPayV3_Key" value="TenPayV3_Key"/>
    <add key="TenPayV3_AppId" value="TenPayV3_AppId"/>
    <add key="TenPayV3_AppSecret" value="TenPayV3_AppSecret"/>
    <add key="TenPayV3_TenpayNotify" value="TenPayV3_TenpayNotify"/>

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved