統一社會信用代碼校正python實現__python

來源:互聯網
上載者:User

新版本營業執照的統一社會信用代碼的規則,

# -*- coding: utf-8 -*-'''Created on 2017年4月5日18位統一社會信用代碼從2015年10月1日正式實行@author: dzm'''# 統一社會信用代碼中不使用I,O,Z,S,VSOCIAL_CREDIT_CHECK_CODE_DICT = {                '0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,                'A':10,'B':11,'C':12, 'D':13, 'E':14, 'F':15, 'G':16, 'H':17, 'J':18, 'K':19, 'L':20, 'M':21, 'N':22, 'P':23, 'Q':24,               'R':25, 'T':26, 'U':27, 'W':28, 'X':29, 'Y':30}# GB11714-1997全國組織機構代碼編製規則中代碼字元集ORGANIZATION_CHECK_CODE_DICT = {                '0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,                'A':10,'B':11,'C':12, 'D':13, 'E':14, 'F':15, 'G':16, 'H':17,'I':18, 'J':19, 'K':20, 'L':21, 'M':22, 'N':23, 'O':24,'P':25, 'Q':26,               'R':27,'S':28, 'T':29, 'U':30,'V':31, 'W':32, 'X':33, 'Y':34,'Z':35}class UnifiedSocialCreditIdentifier(object):    '''    統一社會信用代碼    '''    def __init__(self):        '''        Constructor        '''    def check_social_credit_code(self,code):        '''        校正統一社會信用代碼的校正碼        計算校正碼公式:            C9 = 31-mod(sum(Ci*Wi),31),其中Ci為組織機構代碼的第i位字元,Wi為第i位置的加權因子,C9為校正碼        '''        # 第i位置上的加權因子        weighting_factor = [1,3,9,27,19,26,16,17,20,29,25,13,8,24,10,30,28]        # 本體代碼        ontology_code = code[0:17]        # 校正碼        check_code = code[17]        # 計算校正碼        tmp_check_code = self.gen_check_code(weighting_factor, ontology_code, 31, SOCIAL_CREDIT_CHECK_CODE_DICT)        if tmp_check_code==check_code:            return True        else:            return False    def check_organization_code(self,code):            '''        校正組織機構代碼是否正確,該規則按照GB 11714編製        統一社會信用代碼的第9~17位為主體標識碼(組織機構代碼),共九位字元        計算校正碼公式:            C9 = 11-mod(sum(Ci*Wi),11),其中Ci為組織機構代碼的第i位字元,Wi為第i位置的加權因子,C9為校正碼        @param  code: 統一社會信用代碼        '''        # 第i位置上的加權因子        weighting_factor = [3,7,9,10,5,8,4,2]        # 第9~17位為主體標識碼(組織機構代碼)        organization_code = code[8:17]        # 本體代碼        ontology_code=organization_code[0:8]        # 校正碼        check_code = organization_code[8]        #         print organization_code,ontology_code,check_code        # 計算校正碼        tmp_check_code = self.gen_check_code(weighting_factor, ontology_code, 11, ORGANIZATION_CHECK_CODE_DICT)        if tmp_check_code==check_code:            return True        else:            return False    def gen_check_code(self,weighting_factor,ontology_code, modulus,check_code_dict):        '''        @param weighting_factor: 加權因子        @param ontology_code:本體代碼        @param modulus:  模數        @param check_code_dict: 字元字典        '''        total = 0        for i in range(len(ontology_code)):            if ontology_code[i].isdigit():                print ontology_code[i] ,weighting_factor[i]                total += int(ontology_code[i]) * weighting_factor[i]            else:                total += check_code_dict[ontology_code[i]]*weighting_factor[i]        diff = modulus - total % modulus        print diff        return check_code_dict.keys()[check_code_dict.values()[diff]]if __name__ == '__main__':    u = UnifiedSocialCreditIdentifier()    print u.check_organization_code(code='91421126331832178C')        print u.check_social_credit_code(code='91420100052045470K')

如果按照天眼查是怎麼獲得企業工商資訊的。中說的先自己根據規則群組合統一社會信用代碼,再通過社會信用代碼向國家企業信用資訊公示系統發起爬蟲請求,那麼至少有
4*12*4000*pow(35,8)=432360075000000000種組合,這是要逆天啊,顯然通過這種方式不靠譜

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.