Iv done this using curl on the command line but now trying to implement it in code:
I am trying to connect to alipay and send this directly to the server
https://mapi.alipay.com/gateway.do?/_input_charset=UTF-8¤cy=USD¬ify_url=10.237.221.84:80&out_trade_no=123456789&partner=2088101122136241&sign=760bdzec6y9goq7ctyx96ezkz78287de&subject=Coke&sign_type=MD5&service=create_forex_trade&total_fee=0.01
but the code i have is way to low level to do this efficiently could someone help me??
What I have tried:
#include <qcoreapplication>
#include "sockettest.h"
#include <iostream>
#include <string>
#include <qcoreapplication>
#include <qcryptographichash>
#include <qdebug>
#include <qurl>
#include <qnetworkrequest.h>
#include <qnetworkaccessmanager.h>
#include <qnetworkreply.h>
SocketTest::SocketTest(QObject *parent) : QObject(parent)
{
}
void SocketTest::test()
{
socket = new QTcpSocket(this);
connect(socket, SIGNAL(connected()), this, SLOT(connected()));
connect(socket, SIGNAL(disconnected()), this, SLOT(disconnected()));
connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
connect(socket, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64)));
qDebug() << "Connecting...";
socket->connectToHost("mapi.alipay.com",443);
if (!socket->waitForConnected(1000))
{
qDebug() << "Error: \n\n" << socket->errorString();
}
}
void SocketTest::connected()
{
qDebug() << "Connected!";
QByteArray output;
QByteArray alipay_tran_req;
QByteArray alipay_tran_req2;
alipay_tran_req = "https://mapi.alipay.com/gateway.do?/_input_charset=UTF-8¤cy=USD¬ify_url=10.237.221.84:80&out_trade_no=123456789&partner=2088101122136241&";
alipay_tran_req2 ="&subject=Coke&sign_type=MD5&service=create_forex_trade&total_fee=0.01";
QCryptographicHash CalculateMd5(QCryptographicHash::Md5);
CalculateMd5.addData(output);
output = alipay_tran_req + "sign=" + (CalculateMd5.result().toHex())+ alipay_tran_req2;
qDebug() << "Input String" << output;
qDebug() << socket->write(alipay_tran_req) << socket->write(output);
socket->write(output);
}
void SocketTest::disconnected()
{
qDebug() << "Disconnected!\n";
}
void SocketTest::bytesWritten(qint64 bytes)
{
qDebug() << "\nWe Wrote: \n" << bytes;
}
void SocketTest::readyRead()
{
qDebug() << "\nReading!\n";
qDebug() << socket->readAll();
}