创建订单
请求地址: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加密字符串 |
|
计算签名
#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¬ify_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;
}
进件地址:两头羊支付