コード例 #1
0
     def test_a_Pay01(self):
         """ alipay mybank2渠道条码支付"""
         authcode=input("请扫描支付宝条码:")
         print("条码是:"+authcode)


         payloaddict={'msgType':'pay',
        'requestTimestamp':self.now_time,
        'msgSrc':'NETPAY',
        'msgId':'02S221X0000004992435124935',
        'mid':'898310077779999',
        'tid':'00810001',
        'barCode':authcode,
        'instMid':'POSTONGDEFAULT',
        'totalAmount':'1',
        'refId':'00004992435W',
        'orderDesc':'xyz',
        'goods':[{"quantity":"10","price":"3","goodsCategory":"A001","goodsld":"X001","body":"11","goodsName":"pay+refund"}],
        'merOrderId':self.mer_orderId
         }
         headers = {
             'Content-Type': "application/json",
             'cache-control': "no-cache",
             'Postman-Token': "c10fac27-b245-4d3b-b52d-45e2d9790517"
         }

         SignDispose.getSignDict(SignDispose(), payloaddict, self.signkey, "MD5")

         saleresponse = requests.request("POST", self.url, data=str(payloaddict),headers=headers)
         self.assertIn(saleresponse.json().get("errCode"),"SUCCESS","bar-code fail"+saleresponse.json().get("errCode"))
コード例 #2
0
    def test_a_Pay(self):
        ''' 微信EPCC渠道条码支付 '''
        autocode = input("请扫描微信条码")
        print("条码是" + autocode)
        now_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')


        payloaddict={'msgType':'pay',
        'requestTimestamp':now_time,
        'msgSrc':'NETPAY',
        'msgId':'02S221X0000004992435124935',
        'mid':'898310077770000',
        'tid':'00810001',
        'barCode':autocode,
        'instMid':'POSTONGDEFAULT',
        'totalAmount':'1',
        'refId':'00004992435W',
        'orderDesc':'xyz',
        'goods':[{"quantity":"10","price":"3","goodsCategory":"A001","goodsld":"X001","body":"11","goodsName":"xyz"}],
        'merOrderId':self.mer_orderId
        }

        headers = {
            'Content-Type': "application/json",
            'cache-control': "no-cache",
            'Postman-Token': "c10fac27-b245-4d3b-b52d-45e2d9790517"
        }


        SignDispose.getSignDict(SignDispose(),payloaddict,self.signkey,"MD5")
        saleresponse = requests.request("POST", self.url, data=str(payloaddict))


        self.assertIn(saleresponse.json().get("errCode"),["TARGET_FAIL","SUCCESS"],"支付失败errcode:"+saleresponse.json().get("errCode"))
コード例 #3
0
    def test_c_Refund(self):
        """ 银联微信渠道公众号支付进行退货交易"""
        refunddict = {
            "msgType": "refund",
            "msgSrc": "NETPAY",
            "mid": "898460147840001",
            "merOrderId": mer_orderId,
            "refundAmount": "1",
            "tid": "12345678",
            "instMid": "QRPAYDEFAULT",
            "msgId": "1234567890",
            "requestTimestamp": self.now_time,
            "signType": "SHA256"
        }

        headers = {
            'Content-Type': "application/json",
            'cache-control': "no-cache",
            'Postman-Token': "85ced8b8-2144-4f56-b0c7-e17e4949d6a7"
        }

        refunddict = SignDispose.getSignDict(SignDispose(), refunddict,
                                             self.signkey, 'SHA256')
        response = requests.request("POST",
                                    url2,
                                    data=str(refunddict),
                                    headers=headers)
        print(refunddict)
        print(response.text)
        self.assertEqual(response.json().get("errCode"), "SUCCESS",
                         "微信公众号渠道退款失败")
コード例 #4
0
    def testbarvoid(self):
        tcpClient = socket(AF_INET, SOCK_STREAM)

        tcpClient.connect(ADDR)
        voiddict = {
            "merOrderId": self.mer_orderId,
            "mid": "898310077779999",
            "msgSrc": "ULINK",
            "msgType": "cancel",
            "requestTimestamp": self.now_time,
            "tid": "00810001"
        }
        voiddata = SignDispose.getSignDict(SignDispose(), voiddict, signkey,
                                           "MD5")
        len = str(voiddata).__len__()

        #begin to send message:
        tcpClient.send((str(len).zfill(8) + str(voiddata)).encode("gbk"))
        responseMessage = tcpClient.recv(BUFFSIZE).decode("gbk")
        responseMessage = responseMessage[8:]
        print(responseMessage)
        self.assertEqual(
            json.loads(responseMessage).get("errCode"), "SUCCESS",
            "void-CASE fail")
        tcpClient.close()
コード例 #5
0
 def testQRCodeQuery(self):
     """  发起二维码支付结果查询,查询成功 """
     queryload = {
         'msgType': 'bills.query',
         'msgSrc': 'NETPAY',
         'mid': '898310077778888',
         'billDate': self.now_date,
         'billNo': billNo,
         'tid': '12345678',
         'instMid': 'QRPAYDEFAULT',
         'requestTimestamp': self.now_time,
         'signType': 'SHA256'
     }
     headers = {
         'Content-Type': "application/json",
         'cache-control': "no-cache",
         'Postman-Token': "d7c1fc99-98e7-4c7c-8d3e-6d859ecaeeeb"
     }
     queryloaddict = SignDispose.getSignDict(SignDispose(), queryload,
                                             self.signkey, self.encryption)
     response = requests.request("POST",
                                 url,
                                 data=str(queryloaddict),
                                 headers=headers)
     print(response.text)
     self.assertEqual(response.json().get("errCode"), "SUCCESS",
                      "支付成功,查询成功")
    def test_c_Refund(self):
        """ 微信EPCC渠道条码支付退货接口"""
        now_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        sleep(10)

        refundload = "{\"merOrderId\":\"" + self.mer_orderId + "\",\"mid\":\"898310077770000\", \
        \"refundAmount\":\"1\",\"msgSrc\":\"NETPAY\",\"msgType\":\"refund\",\"requestTimestamp\":\"" + now_time + "\",\"tid\":\"00000001\"}"

        headers = {
            'Content-Type': "application/json",
            'cache-control': "no-cache",
            'Postman-Token': "c10fac27-b245-4d3b-b52d-45e2d9790517"
        }

        refundloaddict = SignDispose.getSignDict(SignDispose(),
                                                 json.loads(refundload),
                                                 self.signkey, "MD5")
        print("请求报文:" + str(refundloaddict))
        response = requests.request("POST",
                                    self.url,
                                    data=str(refundloaddict),
                                    headers=headers)

        self.assertIn(response.json().get("errCode"), "SUCCESS",
                      "refund fail:" + response.json().get("errCode"))
 def test_b_Query(self):
     " " " 微信EPCC渠道条码支付查询" ""
     now_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
     payquery = "{\"merOrderId\":\"" + self.mer_orderId + "\"," \
                                                     "\"mid\":\"898310077770000\"," \
                                                     "\"msgSrc\":\"NETPAY\"," \
                                                     "\"msgType\":\"query\"," \
                                                     "\"requestTimestamp\":\"" + now_time + "\"," \
                                                                                                 "\"tid\":\"00000001\"}"
     headers = {
         'cache-control': "no-cache",
         'Postman-Token': "37db237c-1d7a-4e70-9179-fa4b7ae27559"
     }
     payquerydict = SignDispose.getSignDict(SignDispose(),
                                            json.loads(payquery),
                                            self.signkey, "MD5")
     response = requests.request("POST",
                                 self.url,
                                 data=str(payquerydict),
                                 headers=headers)
     print(response.text)
     self.assertEqual(
         response.json().get("errCode"), "SUCCESS",
         "barcode-query-unionpay case test result is:--" +
         response.json().get("errCode"))
コード例 #8
0
    def test_b_Query(self):
        ''' 支付宝银联渠道条码支付查询 json实现接口'''
        payquery = "{\"merOrderId\":\"" + self.mer_orderId + "\"," \
                                                             "\"mid\":\"898310077774444\"," \
                                                             "\"msgSrc\":\"NETPAY\"," \
                                                             "\"msgType\":\"query\"," \
                                                             "\"requestTimestamp\":\"" + self.now_time + "\"," \
                                                                                                         "\"tid\":\"00000001\"}"

        headers = {
            'Content-Type': "application/json",
            'cache-control': "no-cache",
            'Postman-Token': "c10fac27-b245-4d3b-b52d-45e2d9790517"
        }
        payquerydict = SignDispose.getSignDict(SignDispose(),
                                               json.loads(payquery),
                                               self.signkey, "MD5")
        response = requests.request("POST",
                                    self.url,
                                    data=json.dumps(payquerydict),
                                    headers=headers)
        print(response.text)

        self.assertIn(response.json().get("errCode"), ["SUCCESS"],
                      "test result:" + response.json().get("errCode"))
コード例 #9
0
    def test_c_QRCodeRefund(self):
        """ 银联二维码ACP渠道交易发起退货交易"""
        refunddict={
            "msgType": "bills.refund",
            "msgSrc": "NETPAY",
            "mid": "898310077778888",
            "billDate": self.now_date,
            "billNo": billNo,
            "refundAmount": "1",
            "tid": "12345678",
            "instMid": "QRPAYDEFAULT",
            "msgId": "1234567890",
            "requestTimestamp": self.now_time,
            "signType": "SHA256"

        }

        headers = {
            'Content-Type': "application/json",
            'cache-control': "no-cache",
            'Postman-Token': "85ced8b8-2144-4f56-b0c7-e17e4949d6a7"
        }

        refunddict=SignDispose.getSignDict(SignDispose(),refunddict,self.signkey,'SHA256')
        response = requests.request("POST", url, data=str(refunddict), headers=headers)
        print(refunddict)
        print(response.text)
        self.assertEqual(response.json().get("errCode"), "SUCCESS","支付宝银联渠道退款失败")
コード例 #10
0
    def test_a_getOnceQRCode(self):
        """ 获取一次性二维码,并发起银联二维码渠道前台支付"""
        payload = "{\"mid\":\"898310077778888\"," \
                  "\"msgSrc\":\"NETPAY\"," \
                  "\"msgType\":\"bills.getQRCode\"," \
                  "\"notifyUrl\":\"http://www.baidu3.com\"," \
                  "\"orderDesc\":\"测试交易\"," \
                  "\"requestTimestamp\":\"" + self.now_time + "\"," \
                                                         "\"billNo\":\"" + billNo + "\"," \
                                                                                    "\"totalAmount\":\"1\",\"tid\":\"00000001\"," \
                                                                                    "\"instMid\":\"QRPAYDEFAULT\"}"
        headers = {
            'Content-Type': "application/json",
            'cache-control': "no-cache",
            'Postman-Token': "e86a132b-d502-4ae4-b4e5-b2ebd2360df1"
        }
        payloaddict = SignDispose.getSignDict(SignDispose(), json.loads(payload), self.signkey,'MD5')
        payload = str(payloaddict)
        response = requests.request("POST", url, data=payload.encode('utf-8'), headers=headers)
        #print(response.text)
        # img = qrcode.make(response.json().get("billQRCode"))
        # img.save("./onceqrcode.png")
        # image = Image.open("./onceqrcode.png")
        # image.resize((360, 360)).show()
        #sleep(20)

        ##二维码的高级用法
        QRCodeWithLogo.getQRCode(QRCodeWithLogo(),response.json().get("billQRCode"),"onceqrcode.png","nfc.png")
        Image.open("onceqrcode.png").resize((360,360)).show()
コード例 #11
0
    def testH5Pay(self):
        now_time = time.strftime('%Y-%m-%d %H:%M:%S')
        querystring = {
            "msgType": "trade.h5Pay",
            "merAppId": "http%3A%2F%2Fwww.wangzhenongyao.com",
            "requestTimestamp": now_time,
            "msgSrc": "NETPAY",
            "mid": "898310077779999",
            "tid": "12345678",
            "instMid": "H5DEFAULT",
            "totalAmount": "1",
            "sceneType": "AND_WAP",
            "merOrderId": self.mer_orderId,
            "merAppName": "wangzhenongyao",
            "returnUrl":
            "https://qr-test3.chinaums.com/netpay-portal/alipay2/h5Pay.do",
            "signType": "MD5"
        }

        SignDispose.getSignDict(SignDispose(), querystring, self.signkey,
                                "MD5")

        payload = ""
        headers = {
            'User-Agent': "MicroMessenger/4.5.255",
            'HTTP_USER_AGENT': "HTTP_USER_AGENT",
            'cache-control': "no-cache",
            'Postman-Token': "d810ccfc-58aa-43ee-ae42-c51c3151d92c"
        }

        response = requests.request("GET",
                                    self.url,
                                    data=payload,
                                    headers=headers,
                                    params=querystring)

        print(response.url)

        #将重定向链接转成二维码扫一扫,使用qycode 和 pil的高级用法
        QRCodeWithLogo.getQRCode(QRCodeWithLogo(), response.url,
                                 "h5qrcode.png", "h5icon.png")
        Image.open("h5qrcode.png").resize((360, 360)).show()
コード例 #12
0
    def test_b_Refund(self):
        ''' 微信EPCC渠道条码支付退货和退货查询'''
        now_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        refundload = "{\"merOrderId\":\""+self.mer_orderId+"\",\"mid\":\"898310077770000\", \
                    \"refundAmount\":\"1\",\"msgSrc\":\"NETPAY\",\"msgType\":\"refund\",\"requestTimestamp\":\""+now_time+"\",\"tid\":\"00000001\"}"

        voidDict = SignDispose.getSignDict(SignDispose(),json.loads(refundload),self.signkey,"MD5")
        response = requests.request("POST", self.url, data=str(voidDict))
        print("退货应答:"+response.text)
        return response.json().get("refundOrderId")


        self.assertIn(response.json().get("errCode"),["SUCCESS","TARGET_FAIL"],"refund fail"+response.json().get("errCode"))
コード例 #13
0
    def test_b_BarVoid(self):
        ''' 银联云闪付UAC条码支付撤销'''
        voidload = "{\"merOrderId\":\"" + self.mer_orderId + "\",\"mid\":\"104310073996272\", \
    \"msgSrc\":\"NETPAY\",\"msgType\":\"cancel\",\"requestTimestamp\":\""+self.now_time+"\",\"tid\":\"00000001\"}"
        headers = {
            'Content-Type': "application/json",
            'cache-control': "no-cache",
            'Postman-Token': "c10fac27-b245-4d3b-b52d-45e2d9790517"
        }

        voidDict=SignDispose.getSignDict(SignDispose(), json.loads(voidload), self.signkey, "MD5")
        response = requests.request("POST", self.url, data=str(voidDict),headers=headers)
        print(response.text)
        self.assertIn(response.json().get("errCode"), ["SUCCESS", "TARGET_FAIL"],
                      "void fail" + response.json().get("errCode") )
コード例 #14
0
    def test_c_RefundQuery(self):
        """ wechat-epcc-refundquery"""
        now_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

        refundqueryload = "{\"merOrderId\":\""+self.test_b_Refund()+"\",\"mid\":\"898310077770000\", \
                            \"refundAmount\":\"1\",\"msgSrc\":\"NETPAY\",\"msgType\":\"refundQuery\",\"requestTimestamp\":\""+now_time+"\",\"tid\":\"00000001\"}"
        print("退货查询请求:"+refundqueryload)

        refundqueryDict = SignDispose.getSignDict(SignDispose(), json.loads(refundqueryload), self.signkey, "MD5")
        refundqueryresponse = requests.request("POST", self.url, data=str(refundqueryDict))

        print("退货查询应答:"+refundqueryresponse.text)



        self.assertIn(refundqueryresponse.json().get("errCode"), ["SUCCESS", "TARGET_FAIL"],
                      "refund query fail" + refundqueryresponse.json().get("errCode"))
コード例 #15
0
    def test_b_BarQuery(self):
        ''' 翼支付直连条码支付查询'''
        queryload = "{\"merOrderId\":\"" + self.mer_orderId + "\",\"mid\":\"898310077771111\", \
    \"msgSrc\":\"NETPAY\",\"msgType\":\"query\",\"requestTimestamp\":\"" + self.now_time + "\",\"tid\":\"00000001\"}"
        headers = {
            'Content-Type': "application/json",
            'cache-control': "no-cache",
            'Postman-Token': "c10fac27-b245-4d3b-b52d-45e2d9790517"
        }

        queryloadDict = SignDispose.getSignDict(SignDispose(),
                                                json.loads(queryload),
                                                self.signkey, "MD5")
        response = requests.request("POST",
                                    self.url,
                                    data=str(queryloadDict),
                                    headers=headers)
        print(response.text)
        self.assertIn(response.json().get("errCode"), "SUCCESS",
                      "void fail" + response.json().get("errCode"))
コード例 #16
0
 def test_b_Querypay(self):
     """ 对支付过的交易进行查询"""
     payquery= "{\"merOrderId\":\""+mer_orderId+"\"," \
       "\"mid\":\"898340149000030\"," \
       "\"msgSrc\":\"NETPAY\"," \
       "\"msgType\":\"query\"," \
       "\"requestTimestamp\":\""+self.now_time+"\"," \
       "\"tid\":\"00000001\"}"
     headers = {
         'cache-control': "no-cache",
         'Postman-Token': "37db237c-1d7a-4e70-9179-fa4b7ae27559"
     }
     payquerydict = SignDispose.getSignDict(SignDispose(),
                                            json.loads(payquery),
                                            self.signkey, 'MD5')
     response = requests.request("POST",
                                 url2,
                                 data=str(payquerydict),
                                 headers=headers)
     print(response.text)
     self.assertEqual(response.json().get("errCode"), "SUCCESS", "查询失败")
コード例 #17
0
    def testbarPay(self):
        tcpClient = socket(AF_INET, SOCK_STREAM)

        tcpClient.connect(ADDR)
        authcode = input("请扫描条码:")
        print("条码是:" + authcode)
        data = {
            'msgType': 'pay',
            'requestTimestamp': self.now_time,
            'msgSrc': 'ULINK',
            'msgId': '02S221X0000004992435124935',
            'mid': '898310077779999',
            'tid': '00810001',
            'barCode': authcode,
            'instMid': 'POSTONGDEFAULT',
            'totalAmount': '1',
            'refId': '00004992435W',
            'orderDesc': 'xyz',
            'merOrderId': self.mer_orderId
        }
        readydata = SignDispose.getSignDict(SignDispose(), data, signkey,
                                            "MD5")
        len = str(readydata).__len__()
        print(len)
        #对于纯数字,可以用格式化方法补0
        s = "%08d" % len
        print(s)

        #对于string,使用zfill()方法补0
        #开始发送接收报文...
        tcpClient.send((str(len).zfill(8) + str(readydata)).encode("gbk"))
        responseMessage = tcpClient.recv(BUFFSIZE).decode("gbk")
        responseMessage = responseMessage[8:]
        print(responseMessage)
        print(json.loads(responseMessage).get("errCode"))
        self.assertEqual(
            json.loads(responseMessage).get("errCode"), "SUCCESS",
            "pay-CASE fail")

        tcpClient.close()
コード例 #18
0
    def test_c_Refund(self):
        """ 银联云闪付ACP渠道条码支付退货接口"""

        refundload = "{\"merOrderId\":\"" + self.mer_orderId + "\",\"mid\":\"898310148160568\", \
        \"refundAmount\":\"1\",\"msgSrc\":\"NETPAY\",\"msgType\":\"refund\",\"requestTimestamp\":\"" + self.now_time + "\",\"tid\":\"00000001\"}"

        headers = {
            'Content-Type': "application/json",
            'cache-control': "no-cache",
            'Postman-Token': "c10fac27-b245-4d3b-b52d-45e2d9790517"
        }

        refundloaddict = SignDispose.getSignDict(SignDispose(),
                                                 json.loads(refundload),
                                                 self.signkey, "MD5")
        response = requests.request("POST",
                                    self.url,
                                    data=str(refundloaddict),
                                    headers=headers)

        self.assertIn(response.json().get("errCode"),
                      ["SUCCESS", "TARGET_FAIL"],
                      "refund fail" + response.json().get("errCode"))