Ejemplo n.º 1
0
def exec_pay_signature(app_id, package, officalaccount):
    app_sercert = ""
    app_key = ""
    mch_id = ""
    if officalaccount:
        mch_id = officalaccount.wx_mch_id
        mch_key = officalaccount.wx_mch_secret
        app_sercert = officalaccount.wx_appsecret
        data_post = {}
        data_post.update({
            'package': "prepay_id=" + package,
            'timeStamp': str(int(time.time())),
            'nonceStr': util.random_generator(),
            'appId': app_id,
            'signType': "MD5"
        })
        _, prestr = util.params_filter(data_post)
        print prestr
        data_post['paySign'] = util.build_mysign(prestr, mch_key, 'MD5')
        result = json.dumps(data_post)
        print result
        return result
    else:
        msg = "服务号信息出错"
        raise ValidationError("%s,%s" % (msg, ""))
Ejemplo n.º 2
0
 def weixin_validate_data(self, postdata):
     cr, uid, context = request.cr, request.uid, request.context
     json = {}
     for el in etree.fromstring(postdata):
         json[el.tag] = el.text
     try:
         appid = json['appid']
         _KEY = request.env['payment.acquirer'].search([
             ('weixin_officialaccount.wx_appid', '=', appid)
         ])[0].weixin_officialaccount.wx_mch_secret
         print _KEY
     except:
         _KEY = "1qaz2wsx3edc4rfv5tgb6yhn7ujm8ik9"
     txs = request.env['payment.transaction'].search([
         ('reference', '=', json['out_trade_no'])
     ])
     if not txs and len(txs) > 1 and txs[0].state == 'done':
         return 'success'
     _, prestr = util.params_filter(json)
     mysign = util.build_mysign(prestr, _KEY, 'MD5')
     if mysign != json.get('sign'):
         _logger.info("签名错误")
         return 'false'
     _logger.info('weixin: validated data')
     return request.registry['payment.transaction'].form_feedback(
         cr, SUPERUSER_ID, json, 'weixin', context=context)
Ejemplo n.º 3
0
 def downloadbill(self, values):
     try:
         appid = values['appid']
         mch_id = values['mch_id']
         mch_secret = values['mch_secret']
         bill_type = 'ALL'
         bill_date = time.strftime('%Y%m%d', time.localtime(time.time()))
         if 'bill_type' in values:
             bill_type = values['bill_type']
         if 'bill_date' in values:
             bill_date = values['bill_date'].replace('-', '')
         nonce_str = util.random_generator()
         data_post = {}
         data_post.update({
             'appid': appid,
             'mch_id': mch_id,
             'nonce_str': nonce_str,
             'bill_type': bill_type,
             'bill_date': bill_date
         })
         _, prestr = util.params_filter(data_post)
         sign = util.build_mysign(prestr, mch_secret, 'MD5')
         data_post['sign'] = sign
         data_xml = "<xml>" + util.json2xml(data_post) + "</xml>"
         url = 'https://api.mch.weixin.qq.com/pay/downloadbill'
         request = urllib2.Request(url, data_xml)
         result = util._try_url(request, tries=3)
         return result
     except Exception as e:
         _logger.error(e)
Ejemplo n.º 4
0
def getbody(data):
    mch_key=data['key']
    del data['key']
    _, prestr = util.params_filter(data)
    print prestr
    print mch_key
    data['sign'] = util.build_mysign(prestr, mch_key, 'MD5')
    data_xml = "<xml>" + (util.json2xml(data)) + "</xml>"
    print data_xml
    return data_xml
Ejemplo n.º 5
0
 def orderquery(self, values):
     try:
         appid = values['appid']
         mch_id = values['mch_id']
         mch_secret = values['mch_secret']
         transaction_id = values['transaction_id']
         nonce_str = util.random_generator()
         data_post = {}
         data_post.update({
             'appid': appid,
             'mch_id': mch_id,
             'transaction_id': transaction_id,
             'nonce_str': nonce_str,
         })
         _, prestr = util.params_filter(data_post)
         sign = util.build_mysign(prestr, mch_secret, 'MD5')
         data_post['sign'] = sign
         data_xml = "<xml>" + util.json2xml(data_post) + "</xml>"
         url = 'https://api.mch.weixin.qq.com/pay/orderquery'
         request = urllib2.Request(url, data_xml)
         result = util._try_url(request, tries=3)
         return result
     except Exception as e:
         _logger.error(e)
Ejemplo n.º 6
0
 def process(self, **post):
     cr, uid, context = request.cr, request.uid, request.context
     parmsdata = request.params
     print parmsdata
     appid = parmsdata['appid']
     mch_id = parmsdata['mch_id']
     env = Environment(request.cr, SUPERUSER_ID, context)
     officialaccount = env['wx.officialaccount'].search([
         ('wx_appid', '=', appid), ('wx_mch_id', '=', mch_id)
     ])
     if officialaccount:
         appkey = officialaccount[0]['wx_mch_secret']
     else:
         appkey = ""
     nonce_str = parmsdata['noncestr']
     body = parmsdata['body']
     out_trade_no = parmsdata['out_trade_no'],
     total_fee = parmsdata['total_fee']
     spbill_create_ip = parmsdata['spbill_create_ip']
     notify_url = parmsdata['notify_url']
     trade_type = parmsdata['trade_type']
     product_id = parmsdata['product_id']
     process_url = parmsdata['process_url']
     notify_url_address = self._notify_url + "db:" + cr.dbname
     data_post = {}
     data_post.update({
         'appid':
         appid,
         'mch_id':
         mch_id,
         'nonce_str':
         nonce_str,
         'body':
         body,
         'out_trade_no':
         body,
         'total_fee':
         total_fee,
         'spbill_create_ip':
         spbill_create_ip,
         'notify_url':
         urlparse.urljoin(notify_url, notify_url_address),
         'trade_type':
         trade_type,
         'product_id':
         product_id,
     })
     if trade_type == "JSAPI":
         opendid = http.request.session['openid']
         print opendid
         data_post.update({'openid': opendid})
     _, prestr = util.params_filter(data_post)
     data_post['sign'] = util.build_mysign(prestr, appkey, 'MD5')
     print data_post
     data_xml = "<xml>" + util.json2xml(data_post) + "</xml>"
     print data_xml
     url = process_url
     requestdata = urllib2.Request(url, data_xml)
     result = util._try_url(requestdata, tries=3)
     weixin_tx_values = {}
     _logger.info(
         "request to %s and the request data is %s, and request result is %s"
         % (url, data_xml, result))
     return_xml = etree.fromstring(result)
     print return_xml
     if return_xml.find('return_code').text == "SUCCESS":
         if return_xml.find('code_url') == None:
             if return_xml.find('prepay_id') == None:
                 err_code = return_xml.find('err_code').text
                 err_code_des = return_xml.find('err_code_des').text
             else:
                 urlinfo = "/shop/confirmation"
                 sale_order_id = request.session.get('sale_last_order_id')
                 if sale_order_id:
                     order = request.registry['sale.order'].browse(
                         cr, SUPERUSER_ID, sale_order_id, context=context)
                 else:
                     return request.redirect('/shop')
                 print order
                 data_info = {}
                 data_info.update({
                     "order":
                     order,
                     "test":
                     "",
                     "appid":
                     appid,
                     "prepay_id":
                     return_xml.find('prepay_id').text,
                     "trade_type":
                     trade_type
                 })
                 request.website.sale_reset(context=context)  # 清除
                 return request.website.render("website_sale.confirmation",
                                               data_info)
                 # raise ValidationError("%s, %s" % (err_code, err_code_des))
         elif return_xml.find('code_url').text == False:
             err_code = return_xml.find('err_code').text
             err_code_des = return_xml.find('err_code_des').text
         else:
             weixin_tx_values['data_xml'] = data_xml
             qrcode = return_xml.find('code_url').text
             weixin_tx_values['qrcode'] = qrcode
             urlinfo = "/shop/confirmation"
             sale_order_id = request.session.get('sale_last_order_id')
             _logger.info("sale_order_id:" + str(sale_order_id))
             if sale_order_id:
                 order = request.registry['sale.order'].browse(
                     cr, SUPERUSER_ID, sale_order_id, context=context)
             else:
                 return request.redirect('/shop')
             print order
             data_info = {}
             data_info.update({
                 "order": order,
                 "test": qrcode,
                 "appid": appid,
                 "prepay_id": return_xml.find('prepay_id').text,
                 "trade_type": trade_type
             })
             request.website.sale_reset(context=context)  # 清除
             return request.website.render("website_sale.confirmation",
                                           data_info)
     else:
         return_code = return_xml.find('return_code').text
         return_msg = return_xml.find('return_msg').text
         raise ValidationError("%s, %s" % (return_code, return_msg))