Esempio n. 1
0
def getUserCode(request):
    try:
        api_pub = JsApi_pub()
        api_pub.setCode(request.GET.get('code'))
        openid = api_pub.getOpenid()
        request.session['openid'] = openid
    except Exception, e:
        with open('/tmp/wni.log', 'a') as f:
            f.write('get user code exception:%s\n' % e)
Esempio n. 2
0
def getjspayparam(request):
    with open('/tmp/wni.log','a') as f:
        f.write('enter getjspayparam func\n')
    try:
        tmp_no = uuid.uuid4().get_hex()
        neworder = UnifiedOrder_pub()
        api_pub = JsApi_pub()
        #url = api_pub.createOauthUrlForCode(reverse('weixin:usercode',args=(tmp_no,),current_app=resolve(request.path).namespace))
        url = api_pub.createOauthUrlForCode('http://eason.happydiaosi.com/weixin/getusercode/%s' % tmp_no)
    except Exception,e:
        with open('/tmp/wni.log','a') as f:
            f.write('create for code url exception:%s\n' % e)
Esempio n. 3
0
def getUserCode_bak(request, trade_no):
    try:
        api_pub = JsApi_pub()
        api_pub.setCode(request.GET.get('code'))
        openid = api_pub.getOpenid()
        neworder = UnifiedOrder_pub()
        #"out_trade_no", "body", "total_fee", "notify_url", "trade_type"
        #tmp_no = uuid.uuid4().get_hex()
        neworder.setParameter('out_trade_no', trade_no)
        neworder.setParameter('body', u'e食部落美食')
        neworder.setParameter('total_fee', '1')
        neworder.setParameter('trade_type', 'JSAPI')
        neworder.setParameter('openid', openid)
        neworder.setParameter('notify_url',
                              'http://efoodin.com/weixin/payback')
        with open('/tmp/wni.log', 'a') as f:
            f.write('neworder params:%s\n' % str(neworder.parameters))
        ppid = neworder.getPrepayId()
        api_pub.setPrepayId(ppid)
        params = api_pub.getParameters()
        trade_no_map[trade_no] = params
        with open('/tmp/wni.log', 'a') as f:
            f.write('js pay param:%s\n' % str(params))
    except Exception, e:
        with open('/tmp/wni.log', 'a') as f:
            f.write('get user code exception:%s\n' % e)
Esempio n. 4
0
def getjspayparam(request):
    try:
        api_pub = JsApi_pub()
        neworder = UnifiedOrder_pub()
        #"out_trade_no", "body", "total_fee", "notify_url", "trade_type"
        trade_no = uuid.uuid4().get_hex()
        neworder.setParameter('out_trade_no', trade_no)
        neworder.setParameter('body', u'e食部落美食')
        #wni: below is for weixin pay test
        #neworder.setParameter('total_fee','1')
        #neworder.setParameter('total_fee',str(request.session.order.total*100))
        #neworder.setParameter('total_fee',str(float(request.session['order']['total']*100)))
        #tmp_total = request.session['order'].get_tmp_total(request)

        order_vars = _order_totals({"request": request})
        #print order_vars["order_total"]
        #neworder.setParameter('total_fee',str(request.session['wni_wxpay_total']*100))
        neworder.setParameter('total_fee',
                              str(int(order_vars['order_total'] * 100)))
        neworder.setParameter('trade_type', 'JSAPI')
        neworder.setParameter('openid', request.session['openid'])
        neworder.setParameter(
            'notify_url', 'http://%s/weixin/payback' % settings.SITE_DOMAIN)
    except Exception, e:
        with open('/tmp/wni.log', 'a') as f:
            f.write('order part exception:%s\n' % str(e))
            f.write('request.order is:%s\n' % str(request.session['order']))
            f.write('request.cart is:%s\n' % str(request.session['cart']))
Esempio n. 5
0
def getjspayparam_bak2(request):
    api_pub = JsApi_pub()
    neworder = UnifiedOrder_pub()
    #"out_trade_no", "body", "total_fee", "notify_url", "trade_type"
    trade_no = uuid.uuid4().get_hex()
    neworder.setParameter('out_trade_no', trade_no)
    neworder.setParameter('body', u'e食部落美食')
    neworder.setParameter('total_fee', '1')
    neworder.setParameter('trade_type', 'JSAPI')
    neworder.setParameter('openid', request.session['openid'])
    neworder.setParameter('notify_url', 'http://efoodin.com/weixin/payback')
    with open('/tmp/wni.log', 'a') as f:
        f.write('neworder params:%s\n' % str(neworder.parameters))
    ppid = neworder.getPrepayId()
    api_pub.setPrepayId(ppid)
    params = api_pub.getParameters()
    return HttpResponse(json.dumps(params))
Esempio n. 6
0
def paytest(request):
    """
    tst_dict = {'pay':'pay','tester':'wni'}
    #neworder = UnifiedOrder_pub()
    api_pub = JsApi_pub()
    #url = api_pub.createOauthUrlForCode(reverse('usercode'))
    #urllib2.urlopen()
    noncestr=createNoncestr()
    jsapi_ticket= getjsapiticket()
    timestamp=int(time.time())
    url=request.path
    sign = getJsconfigSign({'noncestr':noncestr,'jsapi_ticket':jsapi_ticket,'timestamp':timestamp,'url':url})
    #return HttpResponse(json.dumps(tst_dict))
    """
    #return render_to_response('paytest.html')
    api_pub = JsApi_pub()
    url = api_pub.createOauthUrlForCode('http://efoodin.com'+reverse('weixin:usercode'))
    return HttpResponseRedirect(url)
Esempio n. 7
0
def getjspayparam(request):
    api_pub = JsApi_pub()
    neworder = UnifiedOrder_pub()
    #"out_trade_no", "body", "total_fee", "notify_url", "trade_type"
    trade_no = uuid.uuid4().get_hex()
    neworder.setParameter('out_trade_no',trade_no)
    neworder.setParameter('body',u'e食部落美食')
    neworder.setParameter('total_fee','1')
    neworder.setParameter('trade_type','JSAPI')
    neworder.setParameter('openid',request.session['openid'])
    neworder.setParameter('notify_url','http://efoodin.com/weixin/payback')
    with open('/tmp/wni.log','a') as f:
        f.write('neworder params:%s\n'% str(neworder.parameters))
    ppid = neworder.getPrepayId()
    api_pub.setPrepayId(ppid)
    params = api_pub.getParameters()
    
    noncestr=createNoncestr()
    jsapi_ticket= getjsapiticket()
    timestamp=int(time.time())
    #url=request.build_absolute_uri()
    #url = 'http://efoodin.com/weixin/paytest/'
    #url = 'http://efoodin.com/weixin/getusercode/'
    url = request.GET.get('signurl',None)
    with open('/tmp/wni.log','a') as f:
        f.write('url used to sign is:%s\n'% str(url))
    sign = getJsconfigSign({'noncestr':noncestr,'jsapi_ticket':jsapi_ticket,'timestamp':timestamp,'url':url})
    #return HttpResponse(json.dumps(tst_dict))
    tmp_dict = {'appId':APPID, 
    'timestamp': timestamp, 
    'nonceStr': noncestr, 
    'signature': sign}
    tmp_dict['pay_params'] = json.loads(params)
    if debug_weixin:
        with open('/tmp/wni.log','a') as f:
            f.write('\nparams for ajax is:%s\n'% str(tmp_dict))
    return HttpResponse(json.dumps(tmp_dict))
Esempio n. 8
0
def paytest(request):
    tst_dict = {'pay':'pay','tester':'wni'}
    #neworder = UnifiedOrder_pub()
    api_pub = JsApi_pub()
    #url = api_pub.createOauthUrlForCode(reverse('usercode'))
    #urllib2.urlopen()
    noncestr=createNoncestr()
    jsapi_ticket= getjsapiticket()
    timestamp=int(time.time())
    url=request.path
    sign = getJsconfigSign({'noncestr':noncestr,'jsapi_ticket':jsapi_ticket,'timestamp':timestamp,'url':url})
    #return HttpResponse(json.dumps(tst_dict))
    return render_to_response('paytest.html',{'appId':APPID, 
    'timestamp': timestamp, 
    'nonceStr': noncestr, 
    'signature': sign})