Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Signature middleware
class App.SignMiddleware
constructor: (@gameData, callback) ->
@name = 'requestSign'
@sessionKey = null
url: "#{@gameData.endpointUrl}user/getSessionKey"
type: 'POST'
data: @_signRequestParams { userId: @gameData.userId }
callback: (res) =>
@sessionKey = JSON.parse(res.responseText).response.sessionkey
App.AjaxMiddleware.addBeforeHandler @name, (options) =>
@process options
process: (options) -> = {} unless
throw Error 'SessionKey not found!' unless @sessionKey?['userId'] = @gameData.userId['sessionkey'] = @sessionKey
# Sign request params = @_signRequestParams
return options
_signRequestParams: (requestData) ->
encodedParams = Base64.encode JSON.stringify(requestData)
requestData =
params: encodedParams
snsig: CryptoJS.MD5(encodedParams + @gameData.SNSIG_SALT).toString()
return requestData
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.