构造微信请求数据----->XML格式

def buildWeiXinUrl(postData, weiXinIsvPriKey):
    dict = json.loads(postData)
    sortData = ''
    for k,v in dict.items():
        sortData = sortData + k + '=' + str(v) + '&'
    paramUrl = sortData + 'key=' + weiXinIsvPriKey
    sign = hashlib.md5(paramUrl.encode('utf-8')).hexdigest().upper()
    dict['sign'] = sign
    xmlUrl = ''
    for k,v in dict.items():
        if k =='detail':
            xmlUrl=xmlUrl + '<' + k + '><![CDATA[' + str(v) + ']]></' + k + '>'
        else:
            xmlUrl = xmlUrl + '<' + k + '>' + str(v) + '</' + k + '>'
    xmlUrl = '<xml>' + xmlUrl + '</xml>'
    return xmlUrl

解析微信返回的XML格式中的参数

def getValue(xml, domName):
    begin = str(xml).find('<' + domName + '>')
    if (begin == -1):
        return
    end = str(xml).find('</' + domName + '>')
    if (end == -1):
        return
    domNameList = ['total_fee', 'cash_fee', 'refund_fee','settlement_total_fee']
    dom = None
    for d in domNameList:
        if (d == domName):
            dom = xml[begin:end].replace('<' + domName + '>', '').replace(']]>', '')
            return dom
    dom = xml[begin:end].replace('<' + domName + '><![CDATA[', '').replace(']]>', '')
    return dom