中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

2018年做視頻網站網站seo站長工具

2018年做視頻網站,網站seo站長工具,創(chuàng)辦網站,做網站域名費向哪里交技術說明 1.前端:uniapp、vue3 2.接口:PHP8、ThinkPHP8、MySQL8.0 3.微信支付- PHP,官方示例文檔 4.示例代碼的模型及業(yè)務自己進行調整,不要一味的復制粘貼!!! 流程說明 1.小程序調用接口…
技術說明

1.前端:uniapp、vue3

2.接口:PHP8、ThinkPHP8、MySQL8.0

3.微信支付- PHP,官方示例文檔

4.示例代碼的模型及業(yè)務自己進行調整,不要一味的復制粘貼!!!

流程說明

1.小程序調用接口--獲取拉起支付所用參數,生成訂單

2.拉起微信支付

3.支付完成-更改訂單狀態(tài)

參數說明

1.appid - 小程序id

2.mchid -- 商戶號ID

3.certificate_serial -- 證書序列號

4.api_v3_key -- 支付密鑰(v3)

5.apiclient_key.pem --?商戶API私鑰文件,根據微信支付下載器下載即可

6.cert.pem --?微信支付平臺證書文件(注意:此文件必須是手動下載的,具體下載方式下方有說明!!!

其他說明

1.本示例采用微信支付sdk

2.實際情況根據業(yè)務進行調整;

3.通知回調(未能正確返回)

4.其他沒毛病。

項目示例

1.安裝微信支付 wechatpay -- sdk

composer require wechatpay/wechatpay

2.下載微信支付平臺證書文件

(1)下載微信支付平臺證書下載器

(2)進行詳情頁(微信支付平臺證書下載器)

(3)下載CertificateDownloader.php,點擊下方紅框,直接下載文件就行,文件位置隨便放,只要能用php命令運行就行

(4)下載證書,直接復制下面命令,改參數即可。

? ? ? ? -k 支付密鑰(上方參數4)

? ? ? ? -m 商戶號(上方參數2)

? ? ? ? -f 商戶密鑰(上方參數5,需要完整路徑)

? ? ? ? -s 證書序列號(上方參數3)

? ? ? ? -o 生成證書地址(需要本地完整路徑)

php -f ./CertificateDownloader.php --  -k 4202c8***** -m 16***** -f /****/apiclient_key.pem -s 25***** -o /*****/cert/

3.封裝支付類(完整示例如下)

<?phpnamespace app\common\controller;use WeChatPay\Builder;
use WeChatPay\Crypto\AesGcm;
use WeChatPay\Crypto\Rsa;
use WeChatPay\Formatter;
use WeChatPay\Util\PemUtil;/*** @note 微信支付操作*/
class WechatPay
{protected string $spAppid;  //  小程序appidprotected string $spAppSecret;  //  小程序密鑰protected string $merchantId;  //  商戶號protected string $certificateSerial;  //  證書序列號protected string $apiV3Key;  //  APIv3密鑰protected object $instance;  //  實例protected string $merchantPrivateKeyFilePath;public function __construct(){$this->spAppid = config('wechat.sp.appid');$this->spAppSecret = config('wechat.sp.secret');$this->merchantId = config('wechat.pay.mchid');$this->certificateSerial = config('wechat.pay.certificate_serial');$this->apiV3Key = config('wechat.pay.api_v3_key');// 從本地文件中加載「商戶API私鑰」,「商戶API私鑰」會用來生成請求的簽名$this->merchantPrivateKeyFilePath = root_path() . 'wxcert/apiclient_key.pem';if (!file_exists($this->merchantPrivateKeyFilePath)) throw new \Exception('商戶API私鑰文件不存在');$merchantPrivateKeyFilePath = 'file://' . $this->merchantPrivateKeyFilePath;$merchantPrivateKeyInstance = Rsa::from($merchantPrivateKeyFilePath, Rsa::KEY_TYPE_PRIVATE);// 從本地文件中加載「微信支付平臺證書」,用來驗證微信支付應答的簽名$platformCertificateFilePath = root_path() . 'wxcert/cert.pem';if (!file_exists($platformCertificateFilePath)) throw new \Exception('微信支付平臺證書文件不存在');$platformCertificateFilePath = 'file://' . $platformCertificateFilePath;$platformPublicKeyInstance = Rsa::from($platformCertificateFilePath, Rsa::KEY_TYPE_PUBLIC);// 從「微信支付平臺證書」中獲取「證書序列號」$platformCertificateSerial = PemUtil::parseCertificateSerialNo($platformCertificateFilePath);// 構造一個 APIv3 客戶端實例$this->instance = Builder::factory(['mchid' => $this->merchantId,   //  商戶號'serial' => $this->certificateSerial,   //「商戶API證書」的「證書序列號」'privateKey' => $merchantPrivateKeyInstance,'certs' => [$platformCertificateSerial => $platformPublicKeyInstance,],]);}/*** @note 獲取微信支付預交易訂單* @param string $openid 用戶openid* @param string $out_trade_no 訂單號* @param string $notify_url 回調地址* @param float $price 價格* @param string $desc 描述*/public function spPrepayId(string $openid, string $out_trade_no, string $notify_url, float $price = 0.01, string $desc = '訂單'){$prepay_id = '';try {$resp = $this->instance->chain('/v3/pay/transactions/jsapi')->post(['json' => ['mchid' => $this->merchantId,'out_trade_no' => $out_trade_no,'appid' => $this->spAppid,'description' => $desc,'notify_url' => $notify_url,'amount' => ['total' => $price * 100,'currency' => 'CNY'],'payer' => ['openid' => $openid]]]);$res = json_decode($resp->getBody());$prepay_id = $res->prepay_id;} catch (\Exception $e) {// 進行錯誤處理echo $e->getMessage(), PHP_EOL;;if ($e instanceof \GuzzleHttp\Exception\RequestException && $e->hasResponse()) {$r = $e->getResponse();echo $r->getStatusCode() . ' ' . $r->getReasonPhrase(), PHP_EOL;echo $r->getBody(), PHP_EOL, PHP_EOL, PHP_EOL;}echo $e->getTraceAsString(), PHP_EOL;}return $prepay_id;}/*** @note 生成簽名* @param string $prepay_id 預交易訂單* @param string $nonceStr 隨機字符串* @param string $timeStamp 時間戳* @return string*/public function makeSign(string $prepay_id, string $nonceStr, string $timeStamp): string{if (!file_exists($this->merchantPrivateKeyFilePath)) return '';$merchantPrivateKeyFilePath = 'file://' . $this->merchantPrivateKeyFilePath;$merchantPrivateKeyInstance = Rsa::from($merchantPrivateKeyFilePath);$params = ['appId' => $this->spAppid,'timeStamp' => $timeStamp,'nonceStr' => $nonceStr,'package' => 'prepay_id=' . $prepay_id,];$params += ['paySign' => Rsa::sign(Formatter::joinedByLineFeed(...array_values($params)),$merchantPrivateKeyInstance), 'signType' => 'RSA'];return $params['paySign'] ?? '';}/*** @note 回調通知,參數解密* @param string $inWechatpaySignature 微信支付平臺簽名* @param string $inWechatpayTimestamp 微信支付平臺時間戳* @param string $inWechatpayNonce 微信支付平臺隨機串* @param string $inBody 通知內容* @param string $inWechatpaySerial 平臺證書序列號* @param string $inRequestID 請求ID* @return array*/public function notifyDecrypt(string $inWechatpaySignature, string $inWechatpayTimestamp, string $inWechatpayNonce, string $inBody, string $inWechatpaySerial, string $inRequestID = ''): array{// 根據通知的平臺證書序列號,查詢本地平臺證書文件,$platformCertificateFilePath = root_path() . 'wxcert/cert.pem';if (!file_exists($platformCertificateFilePath)) throw new \Exception('微信支付平臺證書文件不存在');$platformCertificateFilePath = 'file://' . $platformCertificateFilePath;$platformPublicKeyInstance = Rsa::from($platformCertificateFilePath, Rsa::KEY_TYPE_PUBLIC);// 檢查通知時間偏移量,允許5分鐘之內的偏移$timeOffsetStatus = 300 >= abs(Formatter::timestamp() - (int)$inWechatpayTimestamp);$verifiedStatus = Rsa::verify(// 構造驗簽名串Formatter::joinedByLineFeed($inWechatpayTimestamp, $inWechatpayNonce, $inBody),$inWechatpaySignature,$platformPublicKeyInstance);if ($timeOffsetStatus && $verifiedStatus) {// 轉換通知的JSON文本消息為PHP Array數組$inBodyArray = (array)json_decode($inBody, true);// 使用PHP7的數據解構語法,從Array中解構并賦值變量['resource' => ['ciphertext' => $ciphertext,'nonce' => $nonce,'associated_data' => $aad]] = $inBodyArray;// 加密文本消息解密$inBodyResource = AesGcm::decrypt($ciphertext, $this->apiV3Key, $nonce, $aad);// 把解密后的文本轉換為PHP Array數組return (array)json_decode($inBodyResource, true);}return [];}/*** @note 加密消息解密*/public function decryptMsg($encryptedData, $iv, $sessionKey): array|string{$pc = new WxBizDataCrypt($this->spAppid, $sessionKey);$errCode = $pc->decryptData($encryptedData, $iv, $data);if ($errCode == 0) {return $data;}return [];}}

4.封裝接口(完整示例如下)

<?phpnamespace app\api\controller\sp;use think\response\Json;class Activity 
{/*** @note 生成訂單*/public function prepayId(): void{$activityId = $this->request->post('ac_id/d', 1);if (empty($activityId)) $this->error('賽事錯誤,請重試!');$openid = $this->request->post('openid/s', '');if (empty($openid)) $this->error('支付用戶獲取失敗,請重試!');$model = new ActivityModel();$activity = $model->findOrEmpty($activityId)->toArray();if (empty($activity)) $this->error('get Err');if ($activity['status'] != 1) $this->error('get Err!');//  訂單信息$orderInfo = ['activity_id' => $activityId,'openid' => $openid,'number' => 'order' . date('YmdHis') . rand(1000, 9999),'money' => $activity['price'],'type' => 1,'status' => 0];//  生成訂單$pay = new WechatPay();$notify_url = env('domain') . 'index.php/api/sp.Activity/notify';$prepayId = $pay->spPrepayId($openid, $orderInfo['number'], $notify_url);if (empty($prepayId)) $this->error('訂單生成失敗,請重試!');$orderInfo['prepay_id'] = $prepayId;$order = new Order();$order->save($orderInfo);$timeStamp = (string)time();$orderInfo['timeStamp'] = $timeStamp;$nonceStr = getRandStr(32);$orderInfo['nonceStr'] = $nonceStr;$orderInfo['package'] = 'prepay_id=' . $prepayId;$orderInfo['paySign'] = $pay->makeSign($prepayId, $nonceStr, $timeStamp);$this->success('get Success', ['order' => $orderInfo]);}/*** @note 支付回調*/public function notify(): Json{$inWechatpaySignature = request()->header('Wechatpay-Signature', ''); // header中獲取簽名$inWechatpayTimestamp = request()->header('Wechatpay-Timestamp', ''); // header中獲取時間戳$inWechatpaySerial = request()->header('Wechatpay-Serial', ''); // header中獲取證書序列號$inWechatpayNonce = request()->header('Wechatpay-Nonce', ''); // header中獲取隨機字符串$inRequestID = request()->header('Request-ID', ''); // 請根據實際情況獲取$inBody = file_get_contents('php://input'); // 請根據實際情況獲取,例如: file_get_contents('php://input');$pay = new WechatPay();$res = $pay->notifyDecrypt($inWechatpaySignature, $inWechatpayTimestamp, $inWechatpayNonce, $inBody, $inWechatpaySerial, $inRequestID);if (!empty($res)) {//  進行訂單數據修改$order = new Order();//  查詢訂單數據$orderInfo = $order->where('number', $res['out_trade_no'])->find();if (!empty($orderInfo)){$result = $order->where('id',$orderInfo['id'])->save(['transaction_id' => $res['transaction_id'],'status' => $res['trade_state'] == 'SUCCESS' ? 1 : 0,'trade_type' => $res['trade_type'],'trade_state_desc' => $res['trade_state_desc'],'bank_type' => $res['bank_type'],'success_time' => $res['success_time']]);cache(':order_' . $res['out_trade_no'], $result, 3600);}return json(['code' => 'SUCCESS']);}return json(['message' => '失敗', 'code' => 'FAIL']);}}

5.uniapp示例

<template><view class="box"><view><up-button text="立即支付" type="primary" @click="toPay"></up-button>    </view><up-toast ref="uToastRef"></up-toast></view>
</template><script setup>import {onLoad} from '@dcloudio/uni-app'import {ref,} from 'vue';import {getPrepayId} from '@/utils/api/order.js'const uToastRef = ref(null)//	點擊支付const toPay = () => {getPrepayId({openid: ''}).then((res) => {if (res.code == 1) {const order = res.data.orderuni.requestPayment({provider: 'wxpay',timeStamp: order.timeStamp, //	時間戳nonceStr: order.nonceStr, //	隨機字符串,長度為32個字符以下package: order.package, //		統(tǒng)一下單接口返回的 prepay_id 參數值,提交格式如:prepay_id=***signType: 'RSA', //	簽名算法,應與后臺下單時的值一致paySign: order.paySign, //	簽名success: function(res) {console.log('success:' + JSON.stringify(res));},fail: function(err) {console.log('fail:' + JSON.stringify(err),);}});} else {uToastRef.value.error(res.msg)}})}
</script><style lang="scss">.box {width: 100%;}
</style>

http://www.risenshineclean.com/news/28448.html

相關文章:

  • 團購網站 seo微信群推廣網站
  • 太湖云建站網站建設職業(yè)培訓機構需要什么資質
  • 外貿網站圖片素材百度網盟推廣怎么做
  • 網頁設計品牌故事昆明百度關鍵詞優(yōu)化
  • 怎么做簡單地網站網站網絡排名優(yōu)化方法
  • 網站建設合同糾紛管轄seo優(yōu)化師就業(yè)前景
  • 營銷型企業(yè)網站建設教案北京競價托管代運營
  • 做網站的實踐報告怎樣制作一個網站
  • wordpress 圖片自動加水印東莞網站制作十年樂云seo
  • 石家莊做外貿網站軟文免費發(fā)布平臺
  • 國際貨代做網站百度通用網址
  • 百度站長工具平臺登錄成都網站建設方案優(yōu)化
  • 網站建站系統(tǒng)站長工具搜索
  • 網站服務公司特點上海疫情又要爆發(fā)了
  • 網站開發(fā)總監(jiān)自助建站
  • 如何做服裝微商城網站建設關鍵字廣告
  • WordPress電影公司網站主題大連網站建設費用
  • 包頭市建設工程安全監(jiān)督站網站萬能搜索引擎入口
  • 東莞網站優(yōu)化微信公眾號運營推廣方案
  • 滾屏網站模板網站生成器
  • 分類網站一天做幾條合適百度平臺客服電話
  • 50個辦廠好項目運城seo
  • 網站正能量晚上免費軟件愛站網為什么不能用了
  • 網站建設技術分為哪些方向電子商務營銷的概念
  • 哪個公司做網站最好深圳百度競價排名系統(tǒng)
  • 有服務器域名源碼怎么做網站平臺sem投放
  • 如何建立微網站詳細seo優(yōu)化操作
  • 網站怎么做讓PC和手機自動識別品牌策劃方案ppt
  • 撫寧區(qū)建設局網站5188關鍵詞平臺
  • 做網站常州網站建設網站定制