Best Python code snippet using localstack_python
wx_pay.py
Source:wx_pay.py
...94 for i in range(0,32) :95 pwd += chars[int((math.floor(random.random() * maxPos)))]96 return pwd97 #è·åé¢æ¯ä»äº¤æä¼è¯æ è¯98 def get_request_payment(self):99 _wx_url = "https://api.mch.weixin.qq.com/pay/unifiedorder"100 # print data101 opener = urllib2.build_opener()102 request = urllib2.Request(103 url = _wx_url,104 headers = {'Content-Type' : 'application/xml','charset':'UTF-8'},105 data = self.data)106 f=opener.open(request)107 # print f.read().decode('utf-8')108 xh = XMLHandler()109 # xml.sax.parseString( f.read().decode('utf-8'), xh)110 xml.sax.parseString( f.read(), xh)111 ret = xh.getDict()112 print ret113 # print ret['err_code_des']114 # print ret['xml']115 # print ret['err_code']116 # print ret['prepay_id']117 # print ret['nonce_str']118 self.timeStamp = str( int(round( time.time() * 1000)) )119 self.package = 'prepay_id=' + ret['prepay_id']120 # self.nonceStr = ret['nonce_str']121 self.nonceStr = self.randomString()122 pmStr = "appId="+ self.APP_ID +"&nonceStr=" + self.nonceStr + "&package=prepay_id=" + ret['prepay_id'] + "&signType=MD5&timeStamp=" + self.timeStamp + "&key=283fc3d9d4b8ba3b58601145466d4417"123 self.paySign = self.md5(pmStr)124 # self.paySign = paySign125 return {126 'timeStamp': self.timeStamp,127 'nonceStr': self.nonceStr,128 'package': self.package,129 'paySign': self.paySign,130 }131 # WxHttp(data)132if __name__ == "__main__":133 # from api.models.user import *134 # from api.models.order import *135 #136 # import django137 # django.setup()138 #139 #140 # session = 'XFTGjxhyrUpZTGyesAz/Lg=='141 # _user = User.objects.get( session = session)142 #143 # print _user144 # _order = Order.objects.get(user_id = _user.id,is_payment = IS_PAYMENT_FALSE) # AddMemberOrder145 #146 # #çæ微信wx_out_trade_no147 # # å½åæ¶é´ + order_id + éæºæ°148 # # _order.wx_out_trade_no = str(datetime.datetime.now().strftime("%Y%m%d%H%M%S")) + str(_order.id) + str(int(random.random() * 1000))149 #150 # wx_out_trade_no = str(datetime.datetime.now().strftime("%Y%m%d%H%M%S")) + str(_order.id) + str(int(random.random() * 1000))151 # print wx_out_trade_no #2017091212253017904152 # print _order.payment_fee, type(_order.payment_fee)153 #154 # fee = str( int( _order.payment_fee * 100) )155 # _wx_pay = wx_pay( _user.wx_open_id , wx_out_trade_no , fee) # æ¯æ¬¡éæ°çæorder.wx_out_trade_no156 # _dict = _wx_pay.get_request_payment()157 # print _dict158 #TODO159 # ä¸ä¸ªæ¥éª¤160 # 1 serveræ¥æ¶å°ç¨åºçMember or Single ï¼å建订å do161 # 2 订åè¿åå°ç¨åºï¼æ¯ä» do162 # 3 æ¯ä»notify_urlå¼æ¥æåéç¥serverï¼è®¢åçæ TODO163 # 4 å°è·å¾æåéç¥ï¼åæå跳转ï¼çæç« or è¿å订åå表 TODO164 dom = '''<table style="border: 1px solid #e0e0e0;" border="1" width="507" cellspacing="0" cellpadding="0" align="center">165 <colgroup > <col width="72" /> <col width="116" /> <col width="102" /> <col span="2" width="72" /> <col width="89" /> <col width="86" /></colgroup>166<tbody >167<tr >168<td colspan="7" width="609" height="45">1ï¼æ¥ä»·åä»¥å¸¦ç¥¨ä»·æ ¼ä¸ºä¸»ï¼æ å为ï¼02æ®çº§æä¼çº§é£ç¨é
ç²¾ï¼æ¥ä»·å°åºä¸ºåæ主产åºå³é
ç²¾ä»·æ ¼ä¸»å¯¼åºãå¦çç±³é
精以ä¸åãåå为主ï¼æ¨è¯é
精以两广ãäºåãåä¸ä¸ºä¸»ï¼ç³èé
精以两广ãäºå为主ã</td>169</tr>170<tr>...
hx_order.py
Source:hx_order.py
...95 _user = user96 _order = order97 _fee = str( int(_order.payment_fee *100) ) #æåæ¢ç®ä¸ºåï¼å¹¶ç¨æ´æ°è¡¨ç¤º98 _wx_pay = wx_pay( _user.wx_open_id , _order.wx_out_trade_no ,_fee , SETTINGS.PAY_CALLBACK_URL)99 _dict = _wx_pay.get_request_payment()100 return _dict101 # ç»è´¹æ¯ä»äºç»´ç ä¿¡æ¯102 def PayRenewWX(self,user,order):103 _user = user104 _order = order105 _fee = str( int(_order.payment_fee *100) ) #æåæ¢ç®ä¸ºåï¼å¹¶ç¨æ´æ°è¡¨ç¤º106 _wx_pay = wx_pay( _user.wx_open_id , _order.wx_out_trade_no ,_fee , SETTINGS.PAY_RENEW_CALLBACK_URL)107 _dict = _wx_pay.get_request_payment()108 return _dict109 # 4-3 微信æ¯ä»åè°110 # æ´æ¹æ°æ®åºä¸ºæ¯ä»æå111 def PayWXCallback(self,_xml):112 xh = XMLHandler()113 xml.sax.parseString( _xml, xh)114 _xml_dict = xh.getDict()115 _out_trade_no = _xml_dict["out_trade_no"]116 _total_fee = _xml_dict["total_fee"]117 #è¿åç»æ118 _xml_resualt = '''119 <xml>120 <return_code><![CDATA[%s]]></return_code>121 <return_msg><![CDATA[%s]]></return_msg>...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!