首页
关于
统计
友联
留言
壁纸
Search
1
微信支付电子发票接入介绍
84 阅读
2
宝塔 设置 SSH 通过密钥登录
83 阅读
3
laravel 使用当中碰到的问题
75 阅读
4
laravel 关于 options请求的处理
62 阅读
5
linux关闭ssh密钥登录(禁止免密登录)
56 阅读
默认分类
后端积累
前端积累
日记
数据库
项目
登录
Search
阳
累计撰写
38
篇文章
累计收到
222
条评论
首页
栏目
默认分类
后端积累
前端积累
日记
数据库
项目
页面
关于
统计
友联
留言
壁纸
搜索到
25
篇与
后端积累
的结果
2021-06-01
微信Native支付V3总结
微信小程序支付 需要先下单https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_1.shtml数据根据文档拼凑下就好了,主要是签名注意这只是下单的签名 /** * 获得下单支付签名 sign */ public function getSign($config,$request,$url){ $url_parts = parse_url($url); $canonical_url = ($url_parts['path'] . (!empty($url_parts['query']) ? "?${url_parts['query']}" : "")); $timestamp = time(); $nonce = makeOrderNo(); $merchant_id = $config['mchid']; $serial_no = $config['serial_no']; $message = 'POST'."\n". $canonical_url."\n". $timestamp."\n". $nonce."\n". json_encode($request )."\n"; $mch_private_key = ($config['mch_key']); openssl_sign($message, $raw_sign, $mch_private_key, 'sha256WithRSAEncryption'); $sign = base64_encode($raw_sign); $schema = 'WECHATPAY2-SHA256-RSA2048'; $token = sprintf('mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"', $merchant_id, $nonce, $timestamp, $serial_no, $sign); return [ 'header'=>'Authorization: '.$schema.' '.$token, 'sign'=>$sign, 'timeStamp'=> $timestamp, 'nonceStr' => $nonce, ]; }讲返回的数据生成二维码,然后下单去支付 对应链接格式:weixin://pay.weixin.qq.com/bizpayurl/up?pr=NwY5Mz9&groupid=00。请商户调用第三方库将code_url生成二维码图片。该模式链接较短,生成的二维码打印到结账小票上的识别率较高。
2021年06月01日
29 阅读
0 评论
1 点赞
2021-06-01
微信小程序支付V3总结
微信小程序支付 需要先下单https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_1.shtml数据根据文档拼凑下就好了,主要是签名注意这只是下单的签名 /** * 获得下单支付签名 sign */ public function getSign($config,$request,$url){ $url_parts = parse_url($url); $canonical_url = ($url_parts['path'] . (!empty($url_parts['query']) ? "?${url_parts['query']}" : "")); $timestamp = time(); $nonce = makeOrderNo(); $merchant_id = $config['mchid']; $serial_no = $config['serial_no']; $message = 'POST'."\n". $canonical_url."\n". $timestamp."\n". $nonce."\n". json_encode($request )."\n"; $mch_private_key = ($config['mch_key']); openssl_sign($message, $raw_sign, $mch_private_key, 'sha256WithRSAEncryption'); $sign = base64_encode($raw_sign); $schema = 'WECHATPAY2-SHA256-RSA2048'; $token = sprintf('mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"', $merchant_id, $nonce, $timestamp, $serial_no, $sign); return [ 'header'=>'Authorization: '.$schema.' '.$token, 'sign'=>$sign, 'timeStamp'=> $timestamp, 'nonceStr' => $nonce, ]; }创建订单之后 还需要小程序唤起支付https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_4.shtml注意最大的坑 这个支付的签名和下单的签名不一样,需要重新生成 /** * 微信小程序支付sign 验签生成 */ function getWXSign($config,$prepay_id){ $timestamp = time(); $nonce = makeOrderNo(); $merchant_id = $config['mchid']; $serial_no = $config['serial_no']; $message = $config['appid']."\n". $timestamp."\n". $nonce."\n". 'prepay_id='.$prepay_id."\n"; $mch_private_key = ($config['mch_key']); openssl_sign($message, $raw_sign, $mch_private_key, 'sha256WithRSAEncryption'); $sign = base64_encode($raw_sign); $schema = 'WECHATPAY2-SHA256-RSA2048'; $token = sprintf('mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"', $merchant_id, $nonce, $timestamp, $serial_no, $sign); return [ 'header'=>'Authorization: '.$schema.' '.$token, 'sign'=>$sign, 'timeStamp'=> $timestamp, 'nonceStr' => $nonce, ]; }余下的自己拼凑下就好了 ,然后去小程序支付
2021年06月01日
32 阅读
0 评论
0 点赞
2021-05-30
workerman启动与停止相关命令
start.php为入口文件一、启动1、以debug(调试)方式启动php start.php start2、以daemon(守护进程)方式启动php start.php start -d二、停止php start.php stop三、重启php start.php restart四、平滑重启php start.php reload五、查看状态php start.php status六、查看连接状态(需要Workerman版本>=3.5.0php start.php connections
2021年05月30日
20 阅读
0 评论
0 点赞
2021-05-30
Native微信支付回调通知v3版
官方文档地址https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_4_5.shtml签名生成https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay4_0.shtml支付回调数据{ "id":"EV-2018022511223320873", "create_time":"2015-05-20T13:29:35+08:00", "resource_type":"encrypt-resource", "event_type":"TRANSACTION.SUCCESS", "resource":{ "algorithm":"AEAD_AES_256_GCM", "ciphertext":"...", "nonce":"...", "original_type":"transaction", "associated_data":"" }, "summary":"支付成功" }猛地一看啥也看不懂 不过文档有介绍参数解密下面详细描述对通知数据进行解密的流程:1、用商户平台上设置的APIv3密钥【微信商户平台—>账户设置—>API安全—>设置APIv3密钥】,记为key;2、针对resource.algorithm中描述的算法(目前为AEAD_AES_256_GCM),取得对应的参数nonce和associated_data;3、使用key、nonce和associated_data,对数据密文resource.ciphertext进行解密,得到JSON形式的资源对象;注: AEAD_AES_256_GCM算法的接口细节,请参考rfc5116。微信支付使用的密钥key长度为32个字节,随机串nonce长度12个字节,associated_data长度小于16个字节并可能为空。这个参考上一篇文章 SHA256签名AEAD_AES_256_GCM解密解密过程需要返回的 resource数组中的 ciphertext,associated_data,nonce 三个数据最终的解密结果 能看懂了,直接用array(12) { ["mchid"]=> string(10) "***" ["appid"]=> string(18) ""***"" ["out_trade_no"]=> string(20) ""***"" ["transaction_id"]=> string(28) ""***"" ["trade_type"]=> string(6) "NATIVE" ["trade_state"]=> string(7) "SUCCESS" ["trade_state_desc"]=> string(12) "支付成功" ["bank_type"]=> string(6) "OTHERS" ["attach"]=> string(28) "order_id=708,method=wxNative" ["success_time"]=> string(25) "2021-05-30T16:46:02+08:00" ["payer"]=> array(1) { ["openid"]=> string(28) '***' } ["amount"]=> array(4) { ["total"]=> int(1) ["payer_total"]=> int(1) ["currency"]=> string(3) "CNY" ["payer_currency"]=> string(3) "CNY" } }
2021年05月30日
33 阅读
0 评论
0 点赞
2021-05-30
SHA256签名AEAD_AES_256_GCM解密
$xmlResult = file_get_contents("php://input");//获取微信的数据 $result = $this->xmlToArray($xmlResult);//将xml转成数组 // 将加密的数据解密,方法在下面 $reqInfo = $this->refund_decrypt($result['req_info']); /* * 退款通知解密 * @Author WangZhaoBo * @param $str 微信同步的加密串req_info * @param $key 商户key */ public function refund_decrypt($str) { $key = md5($this->appSecret); $str = base64_decode($str); $str = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $str, MCRYPT_MODE_ECB); $block = mcrypt_get_block_size('rijndael_128', 'ecb'); $pad = ord($str[($len = strlen($str)) - 1]); $len = strlen($str); $pad = ord($str[$len - 1]); return substr($str, 0, strlen($str) - $pad); }SHA256签名/** * 作用:生成256签名 */ public function get256Sign($Obj,$key = null) { foreach ($Obj as $k => $v) { $Parameters[$k] = $v; } //签名步骤一:按字典序排序参数 ksort($Parameters); $String = $this->formatBizQueryParaMap($Parameters, false); //echo '【string1refund_decrypt】'.$String.'</br>'; //签名步骤二:在string后加入KEY if(is_null($key)){ $key = WxPayConf_pub::$KEY; $String = $String."&key=".WxPayConf_pub::$KEY; }else{ $String = $String."&key=".$key; } echo $String; //签名步骤三:MD5加密 //$String = md5($String); $String = hash_hmac("sha256", $str, $key); //echo "【string3】 ".$String."</br>"; //签名步骤四:所有字符转为大写 $result_ = strtoupper($String); //echo "【result】 ".$result_."</br>"; return $result_; }AEAD_AES_256_GCM的解密php示例代码 (参考:https://pay.weixin.qq.com/wiki/doc/api/xiaowei.php?chapter=19_11和https://blog.csdn.net/u010324331/article/details/82153067和https://pay.weixin.qq.com/wiki/doc/api/download/wxpay_xiaowei_cert.pdf和)//region 证书解密start public function decodePem(){ $ciphertext = '加密后的证书内容'; $nonce = '加密证书的随机串,加密证书的随机串'; $associated_data = '加密证书的随机串,固定值: certificate'; $key = '你的APIv3密钥'; $check_sodium_mod = extension_loaded('sodium'); if($check_sodium_mod === false){ echo '没有安装sodium模块';die; } $check_aes256gcm = sodium_crypto_aead_aes256gcm_is_available(); if($check_aes256gcm === false){ echo '当前不支持aes256gcm';die; } $pem = sodium_crypto_aead_aes256gcm_decrypt(base64_decode($ciphertext),$associated_data,$nonce,$key); var_dump($pem); //这是解密出来的证书内容,复制出来保存就行了 } //endregion 证书解密end 使用sodium_crypto_aead_aes256gcm_decrypt函数需要安装sodium扩展,要求PHP版本必须大于7,小于7的也有这个扩展, 但是没有sodium_crypto_aead_aes256gcm_decrypt这个方法.安装sodium扩展方法pecl install libsodium最后别忘了在 php.ini 中添加extension=sodium.so还是不懂看这里 安装扩展 如果不安装扩展,怎么办? 用paragonie/sodium_compat这个类库.Sodium Compat 是用于 Sodium 加密库(libsodium)的纯 PHP 填充,它是 PHP 7.2.0+ 的核心扩展,也可用于 PECL。这个库 tentativeley 支持PHP 5.2.4 - 7.x(最新版),但官方只支持非 EOL 版本的 PHP。如果安装了 PHP 扩展,Sodium Compat 将机会性地透明地使用 PHP 扩展而不是我们的实现。github 地址: https://github.com/paragonie/sodium_compat其中ParagonIE_Sodium_Compat类下面有一个crypto_aead_aes256gcm_decrypt方法.调用方法ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt($ciphertext,$associated_data,$nonce,$key);
2021年05月30日
32 阅读
0 评论
0 点赞
1
2
3