两头羊支付Api对接文档(C++)

创建订单

请求地址:http://orderapi.liangtouyang.com/api/orders/pay

请求名

类型

参考值

备注

appid

String

100010000

后台应用中心获取

type

int

0

0:微信支付 1:支付宝支付

out_trade_no

string

Y1234567989

用户订单号

money

string

1.00

付款金额,注意必须是标准的金额格式如1.00 1.01

notify_url

string

可填可不填 不填则用后台应用内设置的为准

device

int

1

1:电脑 2:手机 填写的类型会利于接口的返回类型

sign

string

32位的MD5加密字符串

例子内存有SIGN计算公式

计算签名

#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <openssl/md5.h>

// Function to calculate MD5 hash
std::string md5_hash(const std::string& input) {
    unsigned char digest[MD5_DIGEST_LENGTH];
    MD5_CTX md5;
    MD5_Init(&md5);
    MD5_Update(&md5, input.c_str(), input.length());
    MD5_Final(digest, &md5);
    
    char buffer[MD5_DIGEST_LENGTH * 2 + 1];
    for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) {
        snprintf(buffer + (i * 2), 3, "%02x", digest[i]);
    }
    return std::string(buffer);
}

// Function to generate sign
std::string generate_sign(const std::map<std::string, std::string>& params, const std::string& secret_key) {
    // Create a concatenated string from the sorted parameters
    std::string param_string;
    for (const auto& pair : params) {
        param_string += pair.first + "=" + pair.second + "&";
    }
    // Remove the last '&'
    if (!param_string.empty()) {
        param_string.pop_back();
    }
    
    // Append the secret key
    param_string += secret_key;
    
    // Calculate MD5 hash
    return md5_hash(param_string);
}

int main() {
    std::map<std::string, std::string> params = {
        {"appid", "100010000"},
        {"type", "0"},
        {"out_trade_no", "Y1234567989"},
        {"money", "1.00"},
        {"notify_url", ""},
        {"device", "1"}
    };
    std::string secret_key = "your_secret_key_here";
    
    std::string sign = generate_sign(params, secret_key);
    
    std::cout << "Generated sign: " << sign << std::endl;
    
    return 0;
}

查询订单

请求地址:http://orderapi.liangtouyang.com/api/orders/query

请求名

类型

参考值

备注

appid

string

100010000

后台应用处获取

out_trade_no

string

Y123456789

用户自己订单号 (二选一)

trade_no

string

R201400000000000000

平台订单号(二选一)

查询订单 无需sign计算

验证签名

#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <openssl/md5.h>

// Function to calculate MD5 hash
std::string md5_hash(const std::string& input) {
    unsigned char digest[MD5_DIGEST_LENGTH];
    MD5_CTX md5;
    MD5_Init(&md5);
    MD5_Update(&md5, input.c_str(), input.length());
    MD5_Final(digest, &md5);
    
    char buffer[MD5_DIGEST_LENGTH * 2 + 1];
    for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) {
        snprintf(buffer + (i * 2), 3, "%02x", digest[i]);
    }
    return std::string(buffer);
}

// Function to verify sign
bool verify_sign(const std::map<std::string, std::string>& params, const std::string& received_sign, const std::string& secret_key) {
    // Create a concatenated string from the sorted parameters
    std::string param_string;
    for (const auto& pair : params) {
        param_string += pair.first + "=" + pair.second + "&";
    }
    // Remove the last '&'
    if (!param_string.empty()) {
        param_string.pop_back();
    }
    
    // Append the secret key
    param_string += secret_key;
    
    // Calculate MD5 hash and compare
    std::string computed_sign = md5_hash(param_string);
    return computed_sign == received_sign;
}

int main() {
    std::map<std::string, std::string> params = {
        {"appid", "100100001"},
        {"time", "1713760397"},
        {"amount", "1.100"},
        {"status", "1"},
        {"out_trade_no", "y1713760297"},
        {"trade_no", "R240422123135450090"}
    };
    std::string received_sign = "a7762b869a349409616ed4cbc5018dae";
    std::string secret_key = "your_secret_key_here";
    
    bool is_valid = verify_sign(params, received_sign, secret_key);
    
    if (is_valid) {
        std::cout << "签名验证通过" << std::endl;
    } else {
        std::cout << "签名验证失败" << std::endl;
    }
    
    return 0;
}

进件地址:两头羊支付 

 

 

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值