123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- #ifndef __PAY_API__
- #define __PAY_API__
- /************************************************************************/
- /* Copyright (C), 2016-2020, [Jeff], 保留所有权利;
- /* 模 块 名:;
- /* 描 述:;
- /*
- /* 版 本:[V];
- /* 作 者:[Jeff];
- /* 日 期:[3/29/2017];
- /*
- /*
- /* 注 意:;
- /*
- /* 修改记录:[Jeff];
- /* 修改日期:;
- /* 修改版本:;
- /* 修改内容:;
- /************************************************************************/
- #include "http_client.h"
- #include "json_util.h"
- #include <openssl/rsa.h>
- #include <openssl/pem.h>
- #include <openssl/err.h>
- #include <openssl/md5.h>
- #include "tinyxml2.h"
- #include <time.h>
- using namespace tinyxml2;
- #ifndef XRSA_KEY_BITS
- #define XRSA_KEY_BITS (1024)
- #endif
- /** STL map default sort order by key **/
- typedef map<string, string> StringMap;
- extern const string Alipay_default_charset;
- extern const string Alipay_default_url;
- extern const string Alipay_default_sign_type;
- extern const string Alipay_default_version;
- extern const string Alipay_appid;
- extern const string Alipay_method;
- extern const string Alipay_charset;
- extern const string Alipay_signtype;
- extern const string Alipay_sign;
- extern const string Alipay_timestamp;
- extern const string Alipay_version;
- extern const string Alipay_bizcontenr;
- #pragma once
- class PayApi
- {
- public:
- PayApi(void);
- ~PayApi(void);
- // 支付宝公共参数;
- public:
- // 支付宝分配给开发者的应用ID;
- string alipay_appid;
- // 支付宝分配给开发者的应用ID;
- string alipay_privatekey;
- // 商户生成签名字符串所使用的签名算法类型,目前支持RSA2和RSA,推荐使用RSA2;
- string alipay_signtype;
- // 调用的接口版本,固定为:1.0;
- string alipay_version;
- // 请求使用的编码格式,如utf-8,gbk,gb2312等;
- string alipay_charset;
- // 要post提交url;
- string alipay_url;
- // 支付定的公共密钥;
- string alipay_PublicKey;
- // 微信公共参数;
- public:
- // 微信公众账号;
- string wxpay_appid;
- // 微信商户号;
- string wxpay_mchid;
- // 微信子商户号;
- string wxapi_submchid;
- // 微信密钥;
- string wxpay_privatekey;
- public:
- static string base64Encode(const unsigned char *bytes, int len);
- static bool base64Decode(const string &str, unsigned char *bytes, int &len);
- static string rsaSign(const string &content, const string &key);
- static bool rsaVerify(const string &content, const string &sign, const string &key);
- // 支付宝支付;
- public:
- void alipay_setCommonParam(
- const string &appid,
- const string &privatekey,
- const string &signtype,
- const string &charset,
- const string &version,
- const string &url,
- const string &publickey
- );
- string buildContent(const StringMap &contentPairs);
- string alipay_invoke(const string &method, const JsonMap &contentMap, const StringMap &extendParamMap = StringMap());
- JsonMap alipay_Str2JsonMap(string strJson);
- string alipay_invoke(const string &method, const string &content, const StringMap &extendParamMap = StringMap());
- string analyzeAliResponse(const string &responseStr);
- // 微信支付;
- public:
- void wxpay_setCommonParam(const string &appid, const string &mchid, const string &privatekey);
- string wxapi_getSign(StringMap &strMap, string key);
- string wxpay_invoke(const string &method, StringMap &extendParamMap, string key);
- string analyzeWXRespone(const string &respone);
- };
- #endif
|