两头羊支付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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/md5.h>

// Function to calculate MD5 hash
void md5_hash(const char *string, unsigned char output[MD5_DIGEST_LENGTH]) {
    MD5_CTX md5;
    MD5_Init(&md5);
    MD5_Update(&md5, string, strlen(string));
    MD5_Final(output, &md5);
}

// Function to convert MD5 hash to a hexadecimal string
void md5_to_hex(unsigned char hash[MD5_DIGEST_LENGTH], char *output) {
    for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) {
        sprintf(output + (i * 2), "%02x", hash[i]);
    }
    output[MD5_DIGEST_LENGTH * 2] = '\0';
}

// Function to generate sign
void generate_sign(const char *secret_key, char *sign) {
    // Example parameters
    char param_string[] = "appid=100010000&type=0&out_trade_no=Y1234567989&money=1.00&notify_url=&device=1";
    
    // Concatenate parameters with secret key
    char string_to_sign[256];
    snprintf(string_to_sign, sizeof(string_to_sign), "%s%s", param_string, secret_key);
    
    // Generate MD5 hash
    unsigned char hash[MD5_DIGEST_LENGTH];
    md5_hash(string_to_sign, hash);
    
    // Convert hash to hexadecimal string
    md5_to_hex(hash, sign);
}

int main() {
    const char *secret_key = "your_secret_key_here";
    char sign[MD5_DIGEST_LENGTH * 2 + 1];
    
    generate_sign(secret_key, sign);
    
    printf("Generated sign: %s\n", sign);
    
    return 0;
}

 

查询订单

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

请求名

类型

参考值

备注

appid

string

100010000

后台应用处获取

out_trade_no

string

Y123456789

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

trade_no

string

R201400000000000000

平台订单号(二选一)

查询订单 无需sign计算

验证签名

 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/md5.h>

// Function to calculate MD5 hash
void md5_hash(const char *string, unsigned char output[MD5_DIGEST_LENGTH]) {
    MD5_CTX md5;
    MD5_Init(&md5);
    MD5_Update(&md5, string, strlen(string));
    MD5_Final(output, &md5);
}

// Function to convert MD5 hash to a hexadecimal string
void md5_to_hex(unsigned char hash[MD5_DIGEST_LENGTH], char *output) {
    for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) {
        sprintf(output + (i * 2), "%02x", hash[i]);
    }
    output[MD5_DIGEST_LENGTH * 2] = '\0';
}

// Function to verify sign
int verify_sign(const char *data, const char *received_sign, const char *secret_key) {
    // Concatenate data with secret key
    char string_to_sign[256];
    snprintf(string_to_sign, sizeof(string_to_sign), "%s%s", data, secret_key);
    
    // Generate MD5 hash
    unsigned char hash[MD5_DIGEST_LENGTH];
    md5_hash(string_to_sign, hash);
    
    // Convert hash to hexadecimal string
    char computed_sign[MD5_DIGEST_LENGTH * 2 + 1];
    md5_to_hex(hash, computed_sign);
    
    // Compare the computed sign with the received sign
    return strcmp(received_sign, computed_sign) == 0;
}

int main() {
    const char *data = "appid=100100001&time=1713760397&amount=1.100&status=1&out_trade_no=y1713760297&trade_no=R240422123135450090";
    const char *received_sign = "a7762b869a349409616ed4cbc5018dae";
    const char *secret_key = "your_secret_key_here";
    
    int is_valid = verify_sign(data, received_sign, secret_key);
    
    if (is_valid) {
        printf("签名验证通过\n");
    } else {
        printf("签名验证失败\n");
    }
    
    return 0;
}

 进件地址:两头羊支付

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值