|
|
|
@ -1,11 +1,11 @@
|
|
|
|
|
#encoding: utf-8
|
|
|
|
|
class WechatService
|
|
|
|
|
|
|
|
|
|
def template_data(openid, template_id, first, key1, key2, key3, remark="具体内容请点击详情查看网站")
|
|
|
|
|
def template_data(openid, template_id, type, id, first, key1, key2, key3, remark="具体内容请点击详情查看网站")
|
|
|
|
|
data = {
|
|
|
|
|
touser:openid,
|
|
|
|
|
template_id:template_id,
|
|
|
|
|
url:"https://www.trustie.net/",
|
|
|
|
|
url:"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect",
|
|
|
|
|
topcolor:"#FF0000",
|
|
|
|
|
data:{
|
|
|
|
|
first: {
|
|
|
|
@ -33,10 +33,10 @@ class WechatService
|
|
|
|
|
data
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def homework_template(user_id, first, key1, key2, key3, remark="具体内容请点击详情查看网站")
|
|
|
|
|
def homework_template(user_id, type, id, first, key1, key2, key3, remark="具体内容请点击详情查看网站")
|
|
|
|
|
uw = UserWechat.where(user_id: user_id).first
|
|
|
|
|
unless uw.nil?
|
|
|
|
|
data = template_data uw.openid,"3e5Dj2GIx8MOcMyRKpTUEQnM7Tg0ASSCNc01NS9HCGI",first, key1, key2, key3, remark
|
|
|
|
|
data = template_data uw.openid,"3e5Dj2GIx8MOcMyRKpTUEQnM7Tg0ASSCNc01NS9HCGI", type, id, first, key1, key2, key3, remark
|
|
|
|
|
begin
|
|
|
|
|
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
|
|
|
|
|
rescue Exception => e
|
|
|
|
@ -44,12 +44,13 @@ class WechatService
|
|
|
|
|
end
|
|
|
|
|
Rails.logger.info "send over. #{req}"
|
|
|
|
|
end
|
|
|
|
|
Rails.logger.info "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def topic_publish_template(user_id, first, key1, key2, key3, remark="具体内容请点击详情查看网站")
|
|
|
|
|
def topic_publish_template(user_id, type, id, first, key1, key2, key3, remark="具体内容请点击详情查看网站")
|
|
|
|
|
uw = UserWechat.where(user_id: user_id).first
|
|
|
|
|
unless uw.nil?
|
|
|
|
|
data = template_data uw.openid,"oKzFCdk7bsIHnGbscA__N8LPQrBkUShvpjV3-kuwWDQ",first, key1, key2, key3, remark
|
|
|
|
|
data = template_data uw.openid,"oKzFCdk7bsIHnGbscA__N8LPQrBkUShvpjV3-kuwWDQ", type, id,first, key1, key2, key3, remark
|
|
|
|
|
Rails.logger.info "start send template message: #{data}"
|
|
|
|
|
begin
|
|
|
|
|
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
|
|
|
|
@ -58,12 +59,13 @@ class WechatService
|
|
|
|
|
end
|
|
|
|
|
Rails.logger.info "send over. #{req}"
|
|
|
|
|
end
|
|
|
|
|
Rails.logger.info "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def comment_template(user_id, first, key1, key2, key3, remark="具体内容请点击详情查看网站")
|
|
|
|
|
def comment_template(user_id,type, id, first, key1, key2, key3, remark="具体内容请点击详情查看网站")
|
|
|
|
|
uw = UserWechat.where(user_id: user_id).first
|
|
|
|
|
unless uw.nil?
|
|
|
|
|
data = template_data uw.openid,"A_3f5v90-zK73V9Kijm-paDkl9S-NuM8Cf-1UJi92_c",first, key1, key2, key3, remark
|
|
|
|
|
data = template_data uw.openid,"A_3f5v90-zK73V9Kijm-paDkl9S-NuM8Cf-1UJi92_c",type, id,first, key1, key2, key3, remark
|
|
|
|
|
Rails.logger.info "start send template message: #{data}"
|
|
|
|
|
begin
|
|
|
|
|
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
|
|
|
|
@ -72,15 +74,16 @@ class WechatService
|
|
|
|
|
end
|
|
|
|
|
Rails.logger.info "send over. #{req}"
|
|
|
|
|
end
|
|
|
|
|
Rails.logger.info "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def message_update_template(user_id, first, key1, key2, remark="具体内容请点击详情查看网站")
|
|
|
|
|
def message_update_template(user_id, type, id, first, key1, key2, remark="具体内容请点击详情查看网站")
|
|
|
|
|
uw = UserWechat.where(user_id: user_id).first
|
|
|
|
|
unless uw.nil?
|
|
|
|
|
data = {
|
|
|
|
|
touser:uw.openid,
|
|
|
|
|
template_id:"YTyNPZnQD8uZFBFq-Q6cCOWaq5LA9vL6RFlF2JuD5Cg",
|
|
|
|
|
url:"https://www.trustie.net/",
|
|
|
|
|
url:"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect",
|
|
|
|
|
topcolor:"#FF0000",
|
|
|
|
|
data:{
|
|
|
|
|
first: {
|
|
|
|
@ -101,7 +104,6 @@ class WechatService
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Rails.logger.info "start send template message: #{data}"
|
|
|
|
|
begin
|
|
|
|
|
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
|
|
|
|
@ -110,5 +112,6 @@ class WechatService
|
|
|
|
|
end
|
|
|
|
|
Rails.logger.info "send over. #{req}"
|
|
|
|
|
end
|
|
|
|
|
Rails.logger.info "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect"
|
|
|
|
|
end
|
|
|
|
|
end
|