|
|
@@ -2,21 +2,8 @@
|
|
|
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
-use addons\fastchat\library\Chat;
|
|
|
-use alisdk\AliPay;
|
|
|
-use app\admin\model\system\GrantVoucher;
|
|
|
-use app\api\model\massager\Work;
|
|
|
-use app\api\model\order\Order;
|
|
|
-use app\api\service\BDService;
|
|
|
-use app\api\service\CallbackService;
|
|
|
-use app\api\service\MassagerService;
|
|
|
-use app\api\service\ProfitService;
|
|
|
-use app\api\service\StoreService;
|
|
|
-use app\api\service\TencentCloudService;
|
|
|
use app\api\service\WxService;
|
|
|
-use app\api\validate\BaseApiValidate;
|
|
|
use app\common\controller\Api;
|
|
|
-use redis\RedLock;
|
|
|
|
|
|
|
|
|
class Test extends Api
|
|
|
@@ -24,46 +11,54 @@ class Test extends Api
|
|
|
|
|
|
protected $noNeedLogin = ["*"];
|
|
|
|
|
|
- function test1() {
|
|
|
- $order = (new Order())->get(1387);
|
|
|
- $res = (new ProfitService())->profit($order, db("user")->where("id", $order["user_id"])->find());
|
|
|
- if($res->code()) {
|
|
|
- $this->success($res->msg());
|
|
|
- } else {
|
|
|
- $this->success($res->data());
|
|
|
- }
|
|
|
+ function payment()
|
|
|
+ {
|
|
|
+ $service = (new WxService);
|
|
|
+ $SR = $service->appletPay("oQ_977SN3KhBetHY9OPckGP9DNNc", self::getRandomStr(20), "sbsbsb", 0.01);
|
|
|
+ $SR->code() ? $this->success($SR->data()) : $this->error($SR->msg());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ function test1()
|
|
|
+ {
|
|
|
+ self::certificates();
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 获取证书
|
|
|
* @return mixed
|
|
|
*/
|
|
|
- public static function certificates(){
|
|
|
+ public static function certificates()
|
|
|
+ {
|
|
|
//请求参数(报文主体)
|
|
|
- $headers = self::sign('GET','https://api.mch.weixin.qq.com/v3/certificates','');
|
|
|
- $result = self::curl_get('https://api.mch.weixin.qq.com/v3/certificates',$headers);
|
|
|
- $result = json_decode($result,true);
|
|
|
- $aa = self::decryptToString($result['data'][0]['encrypt_certificate']['associated_data'],$result['data'][0]['encrypt_certificate']['nonce'],$result['data'][0]['encrypt_certificate']['ciphertext']);
|
|
|
+ $headers = self::sign('GET', 'https://api.mch.weixin.qq.com/v3/certificates', '');
|
|
|
+ $result = self::curl_get('https://api.mch.weixin.qq.com/v3/certificates', $headers);
|
|
|
+ $result = json_decode($result, true);
|
|
|
+ dump($result);//解密后的内容,就是证书内容
|
|
|
+ $aa = self::decryptToString($result['data'][0]['encrypt_certificate']['associated_data'], $result['data'][0]['encrypt_certificate']['nonce'], $result['data'][0]['encrypt_certificate']['ciphertext']);
|
|
|
var_dump($aa);//解密后的内容,就是证书内容
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 签名
|
|
|
- * @param string $http_method 请求方式GET|POST
|
|
|
- * @param string $url url
|
|
|
- * @param string $body 报文主体
|
|
|
+ * @param string $http_method 请求方式GET|POST
|
|
|
+ * @param string $url url
|
|
|
+ * @param string $body 报文主体
|
|
|
* @return array
|
|
|
*/
|
|
|
- public static function sign($http_method = 'POST',$url = '',$body = ''){
|
|
|
+ public static function sign($http_method = 'POST', $url = '', $body = '')
|
|
|
+ {
|
|
|
$mch_private_key = self::getMchKey();//私钥
|
|
|
$timestamp = time();//时间戳
|
|
|
$nonce = self::getRandomStr(32);//随机串
|
|
|
$url_parts = parse_url($url);
|
|
|
$canonical_url = ($url_parts['path'] . (!empty($url_parts['query']) ? "?${url_parts['query']}" : ""));
|
|
|
//构造签名串
|
|
|
- $message = $http_method."\n".
|
|
|
- $canonical_url."\n".
|
|
|
- $timestamp."\n".
|
|
|
- $nonce."\n".
|
|
|
- $body."\n";//报文主体
|
|
|
+ $message = $http_method . "\n" .
|
|
|
+ $canonical_url . "\n" .
|
|
|
+ $timestamp . "\n" .
|
|
|
+ $nonce . "\n" .
|
|
|
+ $body . "\n";//报文主体
|
|
|
//计算签名值
|
|
|
openssl_sign($message, $raw_sign, $mch_private_key, 'sha256WithRSAEncryption');
|
|
|
$sign = base64_encode($raw_sign);
|
|
|
@@ -71,27 +66,29 @@ class Test extends Api
|
|
|
$config = self::config();
|
|
|
$token = sprintf('WECHATPAY2-SHA256-RSA2048 mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"',
|
|
|
$config['mchid'], $nonce, $timestamp, $config['serial_no'], $sign);
|
|
|
- $headers = [
|
|
|
+ return [
|
|
|
'Accept: application/json',
|
|
|
'User-Agent: */*',
|
|
|
'Content-Type: application/json; charset=utf-8',
|
|
|
- 'Authorization: '.$token,
|
|
|
+ 'Authorization: ' . $token,
|
|
|
];
|
|
|
- return $headers;
|
|
|
}
|
|
|
+
|
|
|
//私钥
|
|
|
- public static function getMchKey(){
|
|
|
- var_dump(file_get_contents("file:///www/wwwroot/pool_ball_baby_server/certificate/wx/apiclient_key.pem"));
|
|
|
+ public static function getMchKey()
|
|
|
+ {
|
|
|
//path->私钥文件存放路径
|
|
|
- return openssl_get_privatekey(file_get_contents("file:///www/wwwroot/pool_ball_baby_server/certificate/wx/apiclient_key.pem"));
|
|
|
+ return openssl_get_privatekey(file_get_contents("file://D:/project_c/billiards-server/certificate/wx/apiclient_key.pem"));
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 获得随机字符串
|
|
|
* @param $len integer 需要的长度
|
|
|
* @param $special bool 是否需要特殊符号
|
|
|
* @return string 返回随机字符串
|
|
|
*/
|
|
|
- public static function getRandomStr($len, $special=false){
|
|
|
+ public static function getRandomStr($len, $special = false)
|
|
|
+ {
|
|
|
$chars = array(
|
|
|
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
|
|
|
"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
|
|
|
@@ -101,7 +98,7 @@ class Test extends Api
|
|
|
"3", "4", "5", "6", "7", "8", "9"
|
|
|
);
|
|
|
|
|
|
- if($special){
|
|
|
+ if ($special) {
|
|
|
$chars = array_merge($chars, array(
|
|
|
"!", "@", "#", "$", "?", "|", "{", "/", ":", ";",
|
|
|
"%", "^", "&", "*", "(", ")", "-", "_", "[", "]",
|
|
|
@@ -112,36 +109,39 @@ class Test extends Api
|
|
|
$charsLen = count($chars) - 1;
|
|
|
shuffle($chars); //打乱数组顺序
|
|
|
$str = '';
|
|
|
- for($i=0; $i<$len; $i++){
|
|
|
+ for ($i = 0; $i < $len; $i++) {
|
|
|
$str .= $chars[mt_rand(0, $charsLen)]; //随机取出一位
|
|
|
}
|
|
|
return $str;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 配置
|
|
|
*/
|
|
|
- public static function config(){
|
|
|
+ public static function config()
|
|
|
+ {
|
|
|
return [
|
|
|
'appid' => '',
|
|
|
- 'mchid' => '1651873606',//商户号
|
|
|
- 'serial_no' => '4C24C6C4B0F88FAB756AA175D720D87A32B6BF23',//证书序列号
|
|
|
+ 'mchid' => '1638097896',//商户号
|
|
|
+ 'serial_no' => '13A336433257E2C58CB5A6BC469B7040EF7E7456',//证书序列号
|
|
|
'description' => '',//应用名称(随意)
|
|
|
'notify' => '',//支付回调
|
|
|
];
|
|
|
}
|
|
|
+
|
|
|
//get请求
|
|
|
- public static function curl_get($url,$headers=array())
|
|
|
+ public static function curl_get($url, $headers = array())
|
|
|
{
|
|
|
$info = curl_init();
|
|
|
- curl_setopt($info,CURLOPT_RETURNTRANSFER,true);
|
|
|
- curl_setopt($info,CURLOPT_HEADER,0);
|
|
|
- curl_setopt($info,CURLOPT_NOBODY,0);
|
|
|
- curl_setopt($info,CURLOPT_SSL_VERIFYPEER,false);
|
|
|
- curl_setopt($info,CURLOPT_SSL_VERIFYPEER,false);
|
|
|
- curl_setopt($info,CURLOPT_SSL_VERIFYHOST,false);
|
|
|
+ curl_setopt($info, CURLOPT_RETURNTRANSFER, true);
|
|
|
+ curl_setopt($info, CURLOPT_HEADER, 0);
|
|
|
+ curl_setopt($info, CURLOPT_NOBODY, 0);
|
|
|
+ curl_setopt($info, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
+ curl_setopt($info, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
+ curl_setopt($info, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
//设置header头
|
|
|
- curl_setopt($info, CURLOPT_HTTPHEADER,$headers);
|
|
|
- curl_setopt($info,CURLOPT_URL,$url);
|
|
|
+ curl_setopt($info, CURLOPT_HTTPHEADER, $headers);
|
|
|
+ curl_setopt($info, CURLOPT_URL, $url);
|
|
|
$output = curl_exec($info);
|
|
|
curl_close($info);
|
|
|
return $output;
|
|
|
@@ -149,17 +149,19 @@ class Test extends Api
|
|
|
|
|
|
const KEY_LENGTH_BYTE = 32;
|
|
|
const AUTH_TAG_LENGTH_BYTE = 16;
|
|
|
+
|
|
|
/**
|
|
|
* Decrypt AEAD_AES_256_GCM ciphertext
|
|
|
*
|
|
|
- * @param string $associatedData AES GCM additional authentication data
|
|
|
- * @param string $nonceStr AES GCM nonce
|
|
|
- * @param string $ciphertext AES GCM cipher text
|
|
|
+ * @param string $associatedData AES GCM additional authentication data
|
|
|
+ * @param string $nonceStr AES GCM nonce
|
|
|
+ * @param string $ciphertext AES GCM cipher text
|
|
|
*
|
|
|
* @return string|bool Decrypted string on success or FALSE on failure
|
|
|
*/
|
|
|
- public static function decryptToString($associatedData, $nonceStr, $ciphertext) {
|
|
|
- $aesKey = '8b70e85dd34b80b2e519eacd7a1abfd8';
|
|
|
+ public static function decryptToString($associatedData, $nonceStr, $ciphertext)
|
|
|
+ {
|
|
|
+ $aesKey = '5a523a148c428bf8c4af91000fc307a6';
|
|
|
$ciphertext = \base64_decode($ciphertext);
|
|
|
if (strlen($ciphertext) <= self::AUTH_TAG_LENGTH_BYTE) {
|
|
|
return false;
|