From d34f4a300276f1e3115fb12d2da5ecc5157f55d5 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Wed, 4 Sep 2019 10:52:21 +0800 Subject: [PATCH] js sdk api --- app/controllers/wechats/js_sdk_signatures_controller.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/wechats/js_sdk_signatures_controller.rb b/app/controllers/wechats/js_sdk_signatures_controller.rb index e4ee0da27..6d7b3d87d 100644 --- a/app/controllers/wechats/js_sdk_signatures_controller.rb +++ b/app/controllers/wechats/js_sdk_signatures_controller.rb @@ -1,7 +1,10 @@ class Wechats::JsSdkSignaturesController < ApplicationController def create - signature = Util::Wechat.js_sdk_signature(params[:url], params[:noncestr], params[:timestamp]) - render_ok(signature: signature) + timestamp = (Time.now.to_f * 1000).to_i + noncestr = ('A'..'z').to_a.sample(8).join + signature = Util::Wechat.js_sdk_signature(params[:url], noncestr, timestamp) + + render_ok(appid: Util::Wechat.appid, timestamp: timestamp, noncestr: noncestr, signature: signature) rescue Util::Wechat::Error => ex render_error(ex.message) end